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