标签:
// 反射调用某个对象的方法
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);
}
标签:
原文地址:http://www.cnblogs.com/netcorner/p/4209918.html