Here you can find the source of getMethodAnnotation(Method method, Class
public static <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationType)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; public class Main { public static <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationType) { T ann = method.getAnnotation(annotationType); if (ann == null) { // Inspect interface methods for (Class iface : method.getDeclaringClass().getInterfaces()) { for (Method otherMethod : iface.getMethods()) { if (isMatchingMethodSignatures(method, otherMethod)) { return getMethodAnnotation(otherMethod, annotationType); }//w w w . jav a 2 s . co m } } } return ann; } /** * @param method * @param otherMethod * @return */ public static boolean isMatchingMethodSignatures(Method method, Method otherMethod) { return calcMethodSignatureHash(method) == calcMethodSignatureHash(otherMethod); } private static int calcMethodSignatureHash(Method m) { return m.getName().hashCode() ^ m.getReturnType().hashCode() ^ Arrays.hashCode(m.getParameterTypes()); } }