Here you can find the source of getMethodConfigByAnnotaton(Object instance, Class> declaringClass, Class extends Annotation> annotationType, Class
public static <T> T getMethodConfigByAnnotaton(Object instance, Class<?> declaringClass, Class<? extends Annotation> annotationType, Class<T> type) throws Throwable
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static <T> T getMethodConfigByAnnotaton(Object instance, Class<?> declaringClass, Class<? extends Annotation> annotationType, Class<T> type) throws Throwable { T result = null;//from w w w.j ava 2 s . com List<Method> methods = new ArrayList<>(); methods.addAll(Arrays.asList(declaringClass.getDeclaredMethods())); methods.addAll(Arrays.asList(declaringClass.getMethods())); for (Method method : methods) { Annotation anno = method.getAnnotation(annotationType); if (anno != null) { method.setAccessible(true); result = (T) method.invoke(instance); break; } } return result; } }