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

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

  1. HOME
  2. Java
  3. R
  4. Reflection Annotation Find
  5. findAnnotation(Class clazz, Class annotationClass)

Description

find Annotation

License

Apache License

Declaration

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

Method Source Code


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

import java.lang.annotation.Annotation;

public class Main {
    public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationClass) {
        A annotation = clazz.getAnnotation(annotationClass);
        if (null != annotation) {
            return annotation;
        }/* ww  w.  j  a  va 2s  .  com*/

        for (Class<?> ifc : clazz.getInterfaces()) {
            annotation = ifc.getAnnotation(annotationClass);
            if (null != annotation) {
                return annotation;
            }
        }

        Class<?> superclass = clazz.getSuperclass();
        if (superclass == null || superclass.equals(Object.class)) {
            return null;
        }

        return findAnnotation(superclass, annotationClass);
    }
}

Related

  1. findAnnotation(Class clazz, Class annotationType)
  2. findAnnotation(Class clazz, Class annotationType)
  3. findAnnotation(Class aClass, Class annotationClass)
  4. findAnnotation(Class classy, Class targetAnnotation)
  5. findAnnotation(Class clazz, Class annotationClass, Set> set)
  6. findAnnotation(Class clazz, Class annotationType)
  7. findAnnotation(Class clazz, Class annotationType)
  8. findAnnotation(Class clazz, Class annotationType)
  9. findAnnotation(Class clazz, Class annotationType)

HOME | Copyright © www.java2s.com 2016