Java Class getAnnotationsByType() Method

The getAnnotationsByType() method of java Class class gets the annotation by type that is associated with this element. If no annotation is related to this element, it returns an array of length 0.

Syntax

Parameter

annotationClass - the Class object corresponding to the annotation type

Returns

Associated annotation type associated with this element, otherwise an array of length zero.

Throws

NullPointerException

Example 1

Test it Now

Output:

[@java.lang.Deprecated()]

Example 2

Test it Now

Output:

MySuperClass Constructor Executing...
subClass Constructor Executing...
[@java.lang.Deprecated()]
[@ClassgetAnnotationsByteExample2$Annotation1()]

Next TopicJava Class




Latest Courses