Java Reflection - Java Constructor .getDeclaredAnnotations ()








Syntax

Constructor.getDeclaredAnnotations() has the following syntax.

public Annotation [] getDeclaredAnnotations()

Example

In the following code shows how to use Constructor.getDeclaredAnnotations() method.

/*  w w  w  . j av a  2  s.c  o  m*/
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class c = Class.forName("java.util.List");

    Constructor[] constructors = c.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++) {
      print_method_or_constructor(constructors[i]);
    }

  }

  public static void print_method_or_constructor(Member member) {
    Constructor c = (Constructor) member;
    Annotation[] types= c.getDeclaredAnnotations();

  }
}