Java Reflection Annotation getAnnotation(Class base, Class annotationClass)

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

Description

get Annotation

License

LGPL

Declaration

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

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.lang.annotation.Annotation;

public class Main {
    public static <T extends Annotation> T getAnnotation(Class<?> base, Class<T> annotationClass) {
        T annotation = null;//ww w. ja  va  2s  .  co m
        annotation = base.getAnnotation(annotationClass);
        if (null != annotation) {
            return annotation;
        }
        Class<?>[] implementees = base.getInterfaces();
        for (int i = 0; null == annotation && i < implementees.length; i++) {
            annotation = implementees[i].getAnnotation(annotationClass);
        }
        return annotation;
    }
}

Related

  1. getAnnotation(Class cls, Class annotationCls)
  2. getAnnotation(Class cls, Class annotationCls)
  3. getAnnotation(Class theExaminedClass, Class theExpectedAnnotation)
  4. getAnnotation(Class anno, Class cl)
  5. getAnnotation(Class annotationClass, Annotation[] annotations)
  6. getAnnotation(Class c, Class annotationClass)
  7. getAnnotation(Class classForAnnotation, Class annotationClass)
  8. getAnnotation(Class clazz, Class annotationClass)
  9. getAnnotation(Class clazz, Class annotationClass)