Java Class getDeclaredAnnotation() Method

21 Mar 2025 | 1 min read

The getDeclaredAnnotation() method of java Class class returns this element's annotation for the specified type if any annotation is directly present otherwise null.

Syntax

Parameter

annotationClass - the Class object corresponding to the annotation type

Returns

annotation for the specified annotation type

Throws

NullPointerException

Example 1

Output:

 @java.lang.Deprecated() null 

Example 2

Output:

 @java.lang.Deprecated() null null null 
 
Next TopicJava Class