public static Method findMethodWith ( Class < ? > searchClass , Class < ? extends Annotation > annotationClass ) { Method foundMethod = null ; methodFinder : while ( searchClass != null && searchClass != Object . class ) { for ( Method method : searchClass . getDeclaredMethods ( ) ) { if ( method . isAnnotationPresent ( annotationClass ) ) { foundMethod = method ; break methodFinder ; } } searchClass = searchClass . getSuperclass ( ) ; } return foundMethod ; }
Return a first occurrence of a method annotated with specified annotation