public static Object invoke ( Object object , String methodName , Object ... parameters ) { Method method = getMethodThatMatchesParameters ( object . getClass ( ) , methodName , parameters ) ; if ( method != null ) { try { return method . invoke ( object , parameters ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( "Unable to invoke method" , e ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( "Unable to invoke method" , e ) ; } catch ( InvocationTargetException e ) { if ( e . getCause ( ) instanceof RuntimeException ) { throw ( RuntimeException ) e . getCause ( ) ; } throw new RuntimeException ( e . getCause ( ) ) ; } } else { throw new RuntimeException ( "No method that matches [" + methodName + "] for class " + object . getClass ( ) . getSimpleName ( ) ) ; } }
Silently invoke the specified methodName using reflection .