Java tutorial
//package com.java2s; import java.lang.reflect.Method; public class Main { static public Object invokeMethod(Object owner, String methodName, Object... args) throws Exception { Class<?> ownerClass = owner.getClass(); Class<?>[] argsClass = null; if (args != null && args.length > 0) { argsClass = new Class<?>[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); if (argsClass[i] == Integer.class) { argsClass[i] = int.class; } else if (argsClass[i] == Boolean.class) { argsClass[i] = boolean.class; } } } Method method = ownerClass.getDeclaredMethod(methodName, argsClass); method.setAccessible(true); return method.invoke(owner, args); } }