Here you can find the source of invokeMethod(Object obj, String method, Object... args)
public static Object invokeMethod(Object obj, String method, Object... args) throws Exception
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Object obj, String method, Object... args) throws Exception { Class<?>[] parameterTypes = new Class<?>[args.length]; if (args.length > 0) for (int i = 0; i < args.length; i++) parameterTypes[i] = args[i].getClass(); Method m = obj.getClass().getMethod(method, parameterTypes); if (!m.isAccessible()) m.setAccessible(true);//from w ww . ja v a2 s .co m return m.invoke(obj, args); } }