Java Class getDeclaredAnnotationsByType() Method

The getDeclaredAnnotationsByType() method of java Class class returns this element's annotation for the specified type if such an annotation is directly present, otherwise null. It ignores inherited annotations.

Syntax

Parameter

annotationClass - the Class object corresponding to the annotation type

Returns

Annotations

Throws

NullPointerException

Example 1

Test it Now

Output:

[@java.lang.Deprecated()]
[@ClassgetDeclaredAnnotationbytypeExample1$Annotation1()]

Example 2

Test it Now

Output:

[@java.lang.Deprecated()]
[@ClassgetDeclaredAnnotationbytypeExample2$Annotation1()]
ClassgetDeclaredAnnotationbytypeExample2.subClass1

Next TopicJava Class




Latest Courses