Java Reflection - Java Constructor .getAnnotation (Class <T> annotationClass)


Constructor.getAnnotation(Class <T> annotationClass) has the following syntax.

public <T extends Annotation> T getAnnotation(Class <T> annotationClass)


In the following code shows how to use Constructor.getAnnotation(Class <T> annotationClass) method.

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
//  w w  w . j a v  a  2 s .c om
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++) {


  public static void print_method_or_constructor(Member member) {
    Constructor c = (Constructor) member;
    Annotation type= c.getAnnotation(Deprecated.class);