Java Reflection Annotation Find findAnnotation(Class clazz, Class annotationClass)

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

Description

find Annotation

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
// The MIT License (MIT)

import java.lang.annotation.Annotation;

public class Main {
    public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) {
        while (clazz != null) {
            T t = clazz.getAnnotation(annotationClass);
            if (t != null) {
                return t;
            }//from ww  w .  j  a v  a2 s  .co m
            for (Class<?> interfaceClass : clazz.getInterfaces()) {
                t = interfaceClass.getAnnotation(annotationClass);
                if (t != null) {
                    return t;
                }
            }
            clazz = clazz.getSuperclass();
        }
        return null;
    }
}

Related

  1. findAnnotation(Class clazz, Class annotationType)
  2. findAnnotation(Class clazz, Class annotationType)
  3. findAnnotation(Class clazz, Class annotationType)
  4. findAnnotation(Class clazz, Class annotationType)
  5. findAnnotation(Class clazz, Class annotationClass)
  6. findAnnotation(Class clazz, Class annotationClass)
  7. findAnnotation(Class clazz, Class annotationType)
  8. findAnnotation(Class klass, Class annotationClass)
  9. findAnnotation(final Class clazz, final Class type)