Java Reflection Annotation getAnnotation(Class clazz, Class annotationType)

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

Description

get Annotation

License

Open Source License

Declaration

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

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> annotationType) {
        T result = clazz.getAnnotation(annotationType);
        if (result == null) {
            Class<?> superclass = clazz.getSuperclass();
            if (superclass != null) {
                return getAnnotation(superclass, annotationType);
            } else {
                return null;
            }/*from  ww  w . j a va  2 s . com*/
        } else {
            return result;
        }
    }
}

Related

  1. getAnnotation(Class clazz, Class annotation)
  2. getAnnotation(Class clazz, Class annotation)
  3. getAnnotation(Class clazz, Class annotationClass)
  4. getAnnotation(Class clazz, Class annotationClass)
  5. getAnnotation(Class clazz, Class annotationClass)
  6. getAnnotation(Class clazz, Class annotationType)
  7. getAnnotation(Class clazz, Class annotationType)
  8. getAnnotation(Class clazz, String fieldName, Class annotationClass)
  9. getAnnotation(Class clazz, String name, Class[] types, Class annotationType)