public static Object invokeMethod ( Class < ? > type , Object instance , String methodName , Class < ? > [ ] inputTypes , Object [ ] input ) { Method method = null ; try { //get method method = type . getDeclaredMethod ( methodName , inputTypes ) ; } catch ( Exception exception ) { throw new FaxException ( "Unable to extract method: " + methodName + " from type: " + type , exception ) ; } //set accessible method . setAccessible ( true ) ; Object output = null ; try { //invoke method output = method . invoke ( instance , input ) ; } catch ( Exception exception ) { throw new FaxException ( "Unable to invoke method: " + methodName + " of type: " + type , exception ) ; } return output ; }
This function invokes the requested method .