Java Reflection - Java Class.getAnnotations()








Syntax

Class.getAnnotations() has the following syntax.

public Annotation [] getAnnotations()

Example

In the following code shows how to use Class.getAnnotations() method.

/*from w w  w. jav  a  2s .  c om*/
import java.lang.annotation.Annotation;

public class Main {

  public static void main(String[] args) {

    Main cls = new Main();
    Class c = cls.getClass();

    Annotation[] a = c.getAnnotations();
    for (Annotation val : a) {
      System.out.println(val.toString());
    }
  }
}