Here you can find the source of getAnnotation(Method method, Class
public static <T extends Annotation> T getAnnotation(Method method, Class<T> annotationClass)
//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; } }