Here you can find the source of invokeMethod(Object source, String method, Collection
public static Object invokeMethod(Object source, String method, Collection<Object> arguments) throws Exception
//package com.java2s; /******************************************************************************* * Copyright (c) 2008 The University of York. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /*from ww w . ja va 2 s. c om*/ * Contributors: * Dimitrios Kolovos - initial API and implementation ******************************************************************************/ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; public class Main { public static Object invokeMethod(Object source, String method, Collection<Object> arguments) throws Exception { Collection<Class<?>> argumentClasses = new ArrayList<Class<?>>(); for (Object argument : arguments) { argumentClasses.add(argument.getClass()); } //Method m = source.getClass().getMethod(method, argumentClasses); if (source == null) return null; for (Method m : source.getClass().getMethods()) { if (m.getName().equalsIgnoreCase(method)) { m.setAccessible(true); return m.invoke(source, arguments.toArray()); } } return null; } }