public static List < Method > findMethodsByNameAndNumParams ( Object object , String method , int numParam ) { LinkedList < Method > list = new LinkedList < Method > ( ) ; Method [ ] methods = object . getClass ( ) . getMethods ( ) ; for ( Method m : methods ) { String methodName = m . getName ( ) ; if ( ignoredMethodNames . indexOf ( methodName ) > - 1 ) { log . debug ( "Skipping method: {}" , methodName ) ; continue ; } if ( log . isDebugEnabled ( ) ) { Class < ? > [ ] params = m . getParameterTypes ( ) ; log . debug ( "Method name: {} parameter count: {}" , methodName , params . length ) ; for ( Class < ? > param : params ) { log . debug ( "Parameter: {}" , param ) ; } } //check parameter length first since this should speed things up if ( m . getParameterTypes ( ) . length != numParam ) { log . debug ( "Param length not the same" ) ; continue ; } //now try to match the name if ( ! methodName . equals ( method ) ) { log . trace ( "Method name not the same" ) ; continue ; } list . add ( m ) ; } return list ; }
Find method by name and number of parameters