Here you can find the source of getMethodsWithAnnotation(Class extends Annotation> type, Class> obj)
public synchronized static Method[] getMethodsWithAnnotation(Class<? extends Annotation> type, Class<?> obj)
//package com.java2s; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; public class Main { public synchronized static Method[] getMethodsWithAnnotation(Class<? extends Annotation> type, Class<?> obj) { return getMethodsWithAnnotation(type, obj, false); }/*from www.j a va2 s . c o m*/ public synchronized static Method[] getMethodsWithAnnotation(Class<? extends Annotation> type, Class<?> obj, boolean includeInterfaces) { Method[] meths = obj.getDeclaredMethods(); ArrayList<Method> methods = new ArrayList<Method>(); for (Method field : meths) { if (field.isAnnotationPresent(type)) { field.setAccessible(true); methods.add(field); } } if (obj.getSuperclass() != null) { Method[] flds2 = getMethodsWithAnnotation(type, obj.getSuperclass(), includeInterfaces); if (flds2.length > 0) { for (int i = 0; i < flds2.length; i++) { methods.add(flds2[i]); } } } if (includeInterfaces) { Class<?>[] interfs = obj.getInterfaces(); for (int i = 0; i < interfs.length; i++) { Class<?> interf = interfs[i]; // for now, no recursion Method[] flds2 = getMethodsWithAnnotation(type, interf); if (flds2.length > 0) { for (int j = 0; j < flds2.length; j++) { methods.add(flds2[j]); } } } } meths = methods.toArray(new Method[methods.size()]); return meths; } }