Here you can find the source of invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args)
@SuppressWarnings("rawtypes") public static Object invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { @SuppressWarnings("rawtypes") public static Object invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args) throws Exception { Class<? extends Object> cl = instance.getClass(); Method method = cl.getDeclaredMethod(methodName, methodParams); method.setAccessible(true);/* w w w . j ava 2 s. c o m*/ Object result = method.invoke(instance, args); return result; } public static Object invoke(final Object instance, final String methodName) throws Exception { Class<? extends Object> cl = instance.getClass(); Method method = cl.getDeclaredMethod(methodName, new Class[0]); method.setAccessible(true); Object result = method.invoke(instance, new Object[0]); return result; } }