Javatpoint Logo
Javatpoint Logo

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA