Java Reflection Annotation getAnnotation(Class clazz, Class annotation)

Here you can find the source of getAnnotation(Class clazz, Class annotation)

Description

get Annotation

License

Open Source License

Declaration

public static <T extends Annotation> T getAnnotation(Class clazz, Class<T> annotation) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.annotation.Annotation;

public class Main {

    public static <T extends Annotation> T getAnnotation(Class clazz, Class<T> annotation) {
        if (clazz.isAnnotationPresent(annotation)) {
            Annotation value = clazz.getAnnotation(annotation);
            return annotation.cast(value);
        }/*from  w  w  w  . j a  v a 2  s  .co  m*/

        return null;
    }
}

Related

  1. getAnnotation(Annotation[] annotaions, Class T)
  2. getAnnotation(Annotation[] annotations, Class annotationType)
  3. getAnnotation(Annotation[] annotations, Class annotationClazz)
  4. getAnnotation(Annotation[] annotations, Class annotationType)
  5. getAnnotation(Annotation[] annotations, Class clazz)
  6. getAnnotation(Class cls, Class annotationCls)
  7. getAnnotation(Class cls, Class annotationCls)
  8. getAnnotation(Class theExaminedClass, Class theExpectedAnnotation)
  9. getAnnotation(Class anno, Class cl)