public static Object invokeMethod ( Object obj , String name , Object ... args ) { if ( obj == null ) throw new NullPointerException ( "Object cannot be null" ) ; if ( name == null ) throw new NullPointerException ( "Method name cannot be null" ) ; Class < ? > objClass = obj . getClass ( ) ; for ( Method method : objClass . getMethods ( ) ) { try { if ( matchMethod ( method , name ) ) return method . invoke ( obj , args ) ; } catch ( Throwable t ) { // Ignore exceptions } } return null ; }
Invokes an object method by its name with specified parameters .