Java Reflection Annotation getAnnotation(Class cls, Class annotationCls)

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

Description

get Annotation

License

Open Source License

Declaration

public static Annotation getAnnotation(Class cls, Class<? extends Annotation> annotationCls) 

Method Source Code


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

import java.lang.annotation.Annotation;

public class Main {
    public static Annotation getAnnotation(Class cls, Class<? extends Annotation> annotationCls) {
        Annotation res = cls.getAnnotation(annotationCls);
        if (res != null) {
            return res;
        } else if (!cls.equals(Object.class)) {
            return getAnnotation(cls.getSuperclass(), annotationCls);
        } else {// w  w  w  . ja  v  a  2s .com
            return null;
        }
    }
}

Related

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