Java Reflection Annotation getAnnotation(Class cls, Class annotationCls)

Here you can find the source of getAnnotation(Class cls, Class annotationCls)

Description

get Annotation

License

Apache License

Declaration

public static Annotation getAnnotation(Class cls, Class annotationCls) 

Method Source Code


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

import java.lang.annotation.Annotation;

public class Main {
    public static Annotation getAnnotation(Class cls, Class annotationCls) {
        if (cls == null) {
            return null;
        }/*from  w w w .  j a v a  2  s .  c om*/
        Annotation ret = cls.getAnnotation(annotationCls);
        if (ret != null) {
            return ret;
        }
        ret = getAnnotation(cls.getSuperclass(), annotationCls);
        if (ret != null) {
            return ret;
        }
        for (Class intrface : cls.getInterfaces()) {
            ret = getAnnotation(intrface, annotationCls);
            if (ret != null) {
                return ret;
            }
        }
        return null;
    }
}

Related

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