Java Reflection Annotation getAnnotation(Method method, Class annotationClass)

Here you can find the source of getAnnotation(Method method, Class annotationClass)

Description

get Annotation

License

Apache License

Declaration

public static <T extends Annotation> T getAnnotation(Method method,
        Class<T> annotationClass) 

Method Source Code

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

import java.lang.annotation.Annotation;
import java.lang.annotation.Inherited;

import java.lang.reflect.Method;

public class Main {

    public static <T extends Annotation> T getAnnotation(Method method,
            Class<T> annotationClass) {
        T t = getAnnotation(method, annotationClass,
                annotationClass.isAnnotationPresent(Inherited.class));
        return t;
    }/*  w  w w.j av  a2 s . com*/

    private static <T extends Annotation> T getAnnotation(Method method,
            Class<T> annotationClass, boolean seekSuper) {
        T t = method.getAnnotation(annotationClass);
        if (t == null && seekSuper) {
            Class<?> clazz = method.getDeclaringClass().getSuperclass();
            if (clazz != null) {
                try {
                    method = clazz.getMethod(method.getName(),
                            method.getParameterTypes());
                    t = getAnnotation(method, annotationClass, true);
                } catch (NoSuchMethodException e) {

                }
            }
        }
        return t;
    }
}

Related

  1. getAnnotation(final Object object, final Class annotationClass)
  2. getAnnotation(Member m, Class annotationClass)
  3. getAnnotation(Method m, Class annotationClass)
  4. getAnnotation(Method method, Class annotationType)
  5. getAnnotation(Method method, Class annotationClass)
  6. getAnnotation(Method method, Class type)
  7. getAnnotation(Object bean, final Class annotation)
  8. getAnnotation(Object context, Class annotation)
  9. getAnnotation(Object instance, Class type)