Here you can find the source of findAnnotationFromMethodOrClass(final Method method, final Class
public static <T extends Annotation> T findAnnotationFromMethodOrClass(final Method method, final Class<T> annotationClass)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; import java.lang.reflect.Method; public class Main { public static <T extends Annotation> T findAnnotationFromMethodOrClass(final Method method, final Class<T> annotationClass) { final T annotation = method.getAnnotation(annotationClass); if (annotation != null) { return annotation; }//from w w w. j a v a 2 s. c o m final Class<?> originClass = method.getDeclaringClass(); return originClass.getAnnotation(annotationClass); } }