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);
}

posted @ 2015-01-08 08:49  netcorner  阅读(868)  评论(0编辑  收藏  举报