Java Constructor .getAnnotation (Class <T> annotationClass)

Syntax

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

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

Example

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;
/*from ww  w  .j  av  a2  s.  c o m*/
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 type= c.getAnnotation(Deprecated.class);

  }
}




















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable