Java Reflection Annotation getAnnotation(Class clazz, Class annotationClass)

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

Description

get Annotation

License

Open Source License

Declaration

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

Method Source Code


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

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Main {
    public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotationClass) {
        T annotation = null;/* w ww. j  a  va  2s .c o  m*/
        if (hasAnnotation(clazz, annotationClass)) {
            annotation = clazz.getAnnotation(annotationClass);
        }
        return annotation;
    }

    public static boolean hasAnnotation(Method method, Class<? extends Annotation> annotation) {
        return method != null && method.isAnnotationPresent(annotation);
    }

    public static boolean hasAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) {
        return clazz != null && clazz.isAnnotationPresent(annotation);
    }
}

Related

  1. getAnnotation(Class clazz, Class ann)
  2. getAnnotation(Class clazz, Class annClazz)
  3. getAnnotation(Class clazz, Class annotation)
  4. getAnnotation(Class clazz, Class annotation)
  5. getAnnotation(Class clazz, Class annotationClass)
  6. getAnnotation(Class clazz, Class annotationClass)
  7. getAnnotation(Class clazz, Class annotationType)
  8. getAnnotation(Class clazz, Class annotationType)
  9. getAnnotation(Class clazz, Class annotationType)