Here you can find the source of invokeMethod2(Class cls, Object obj, String methodName, Object[] args)
public static Object invokeMethod2(Class cls, Object obj, String methodName, Object[] args) throws Exception
//package com.java2s; /******************************************************************************* * Copyright ? 2012-2015 eBay Software Foundation * This program is dual licensed under the MIT and Apache 2.0 licenses. * Please see LICENSE for more information. *******************************************************************************/ import java.lang.reflect.Method; public class Main { public static Object invokeMethod2(Class cls, Object obj, String methodName, Object[] args) throws Exception { Method[] methods = cls.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { method.setAccessible(true); return method.invoke(obj, args); }//w ww . j av a 2 s . c o m } return null; } }