public static Method getMethod ( Class < ? > clazz , final String methodName , final Class < ? > ... parameterTypes ) { final String internedName = methodName . intern ( ) ; return traverseHierarchy ( clazz , new TraverseTask < Method > ( ) { @ Override public Method run ( Class < ? > clazz ) { Method [ ] methods = clazz . getDeclaredMethods ( ) ; Method res = null ; for ( int i = 0 ; i < methods . length ; i ++ ) { Method m = methods [ i ] ; if ( m . getName ( ) == internedName && arrayContentsEq ( parameterTypes , m . getParameterTypes ( ) ) && ( res == null || res . getReturnType ( ) . isAssignableFrom ( m . getReturnType ( ) ) ) ) { res = m ; } } return res ; } } ) ; }
Returns the method object found for the given method name in the given class . This method traverses through the super classes of the given class and tries to find the method as declared method within these classes . When the object class is reached the traversing stops . If the method can not be found null is returned .