Java Reflection - 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 {/*  w  w  w .  j a v  a  2 s  . c om*/
      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.