Here you can find the source of invokeMethod(Class clazz, Object classObject, String methodName, Class[] paramTypes, Object... args)
public static Object invokeMethod(Class clazz, Object classObject, String methodName, Class[] paramTypes, Object... args)
//package com.java2s; //License from project: LGPL import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Class clazz, Object classObject, String methodName, Class[] paramTypes, Object... args) {// w ww. j ava2s.c om try { if (paramTypes == null) { paramTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { if (args[i] instanceof Integer) { paramTypes[i] = int.class; } else { paramTypes[i] = args[i].getClass(); } } } Method m = clazz.getDeclaredMethod(methodName, paramTypes); m.setAccessible(true); return m.invoke(classObject, args); } catch (Exception ex) { System.out.println(ex.getCause() + ", "); ex.printStackTrace(); return null; } } }