java反射调用某个对象的方法
// 反射调用某个对象的方法
public Object invokeMethod(Object methodObject, String methodName,
Object[] args) throws Exception {
Class ownerClass = methodObject.getClass();
Class[] argsClass = new Class[args.length];
for (int i = 0, j = args.length; i < j; i++) {
argsClass[i] = args[i].getClass();
}
Method method = ownerClass.getMethod(methodName, argsClass);
return method.invoke(methodObject, args);
}