Java Class.getAnnotation(Class <A> annotationClass)
Syntax
Class.getAnnotation(Class <A> annotationClass) has the following syntax.
public <A extends Annotation> A getAnnotation(Class <A> annotationClass)
Example
In the following code shows how to use Class.getAnnotation(Class <A> annotationClass) method.
public class Main{
public static void main(String[] unused) {
try {/*w w w . j a v a 2 s .c o m*/
String n = "java.lang.Deprecated";
Class c = Class.forName(n);
Class d = Class.forName("java.util.Date");
System.out.println(d.getAnnotation(c));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.