Java Reflection Annotation getAnnotation(Method method, Class annotationType)

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

  1. HOME
  2. Java
  3. R
  4. Reflection Annotation
  5. getAnnotation(Method method, Class annotationType)

Description

get Annotation

License

Apache License

Declaration

public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) 

Method Source Code

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

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Main {
    public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
        A ann = method.getAnnotation(annotationType);
        if (ann == null) {
            for (Annotation metaAnn : method.getAnnotations()) {
                ann = metaAnn.annotationType().getAnnotation(annotationType);
                if (ann != null) {
                    break;
                }/*from   ww  w . j  a va 2 s .c  om*/
            }
        }
        return ann;
    }

    public static Annotation[] getAnnotations(Method method) {
        return method.getDeclaredAnnotations();
    }
}

Related

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

HOME | Copyright © www.java2s.com 2016