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 . ja v a2s . co 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();
}
}