public static Object invoke ( Method method , Object target , Object [ ] args ) { assertObjectNotNull ( "method" , method ) ; try { return method . invoke ( target , args ) ; } catch ( InvocationTargetException e ) { Throwable t = e . getCause ( ) ; if ( t instanceof RuntimeException ) { throw ( RuntimeException ) t ; } if ( t instanceof Error ) { throw ( Error ) t ; } String msg = "The InvocationTargetException occurred: " ; msg = msg + " method=" + method + " target=" + target ; msg = msg + " args=" + ( args != null ? Arrays . asList ( args ) : "" ) ; throw new ReflectionFailureException ( msg , t ) ; } catch ( IllegalArgumentException e ) { String msg = "Illegal argument for the method:" ; msg = msg + " method=" + method + " target=" + target ; msg = msg + " args=" + ( args != null ? Arrays . asList ( args ) : "" ) ; throw new ReflectionFailureException ( msg , e ) ; } catch ( IllegalAccessException e ) { String msg = "Illegal access to the method:" ; msg = msg + " method=" + method + " target=" + target ; msg = msg + " args=" + ( args != null ? Arrays . asList ( args ) : "" ) ; throw new ReflectionFailureException ( msg , e ) ; } }
Invoke the method by reflection .