private static Method findMethod ( String methodName , Object instance , Class < ? > valueClass , boolean setter ) throws NoSuchMethodException { if ( methodName == null ) { return null ; } int paramCount = setter ? 1 : 0 ; for ( Method method : instance . getClass ( ) . getMethods ( ) ) { if ( method . getName ( ) . equals ( methodName ) && method . getParameterTypes ( ) . length == paramCount ) { Class < ? > targetClass = setter ? method . getParameterTypes ( ) [ 0 ] : method . getReturnType ( ) ; if ( valueClass == null || TypeUtils . isAssignable ( targetClass , valueClass ) ) { return method ; } } } throw new NoSuchMethodException ( "Compatible method not found: " + methodName ) ; }
Returns the requested method from an object instance .