Here you can find the source of invoke(Object instance, Method method, Object... params)
public static Object invoke(Object instance, Method method, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
//package com.java2s; /*//w ww. jav a 2s . com * This file is part of Cotopaxi. * * Cotopaxi is free software: you can redistribute it and/or modify * it under the terms of the Lesser GNU General Public License as published * by the Free Software Foundation, either version 3 of the License, or * any later version. * * Cotopaxi is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * Lesser GNU General Public License for more details. * * You should have received a copy of the Lesser GNU General Public License * along with Cotopaxi. If not, see <http://www.gnu.org/licenses/>. */ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { private static final Class<?>[] EMPTY_CLASS_PARAMS = new Class[0]; /** * Invokes the given object {@link Method}. */ public static Object invoke(Object instance, Method method, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { return method.invoke(instance, params); } public static Object invoke(Object facade, String method, Object... params) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method m = getMethod(facade.getClass(), method, params); return invoke(facade, m, params); } public static Method getMethod(Class<?> klass, String methodName, Object... params) throws SecurityException, NoSuchMethodException { Class<?>[] classes = (params.length != 0) ? new Class<?>[params.length] : EMPTY_CLASS_PARAMS; for (int i = 0; i < params.length; i++) { classes[i] = params[i].getClass(); } return klass.getMethod(methodName, classes); } /** * Gets an {@link Class} by name. */ public static Class<?> getClass(String className) throws ClassNotFoundException { return Class.forName(className); } }