Here you can find the source of invokeMethod(Object object, String methodName, Object[] params, Class... types)
private static Object invokeMethod(Object object, String methodName, Object[] params, Class... types) throws Exception
//package com.java2s; import java.lang.reflect.Method; public class Main { private static Object invokeMethod(Object object, String methodName, Object[] params, Class... types) throws Exception { Object out = null;//from www . ja v a 2 s .c om Class c = object instanceof Class ? (Class) object : object .getClass(); if (types != null) { Method method = c.getMethod(methodName, types); out = method.invoke(object, params); } else { Method method = c.getMethod(methodName); out = method.invoke(object); } //System.out.println(object.getClass().getName() + "." + methodName + "() = "+ out); return out; } }