Java Class getDeclaredAnnotation() Method

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

Test it Now

Output:

@java.lang.Deprecated()
null

Example 2

Test it Now

Output:

@java.lang.Deprecated()
null
null
null

Next TopicJava Class




Latest Courses