本帖最后由 徐启坤 于 2013-6-8 21:15 编辑
张老师的这段代码中有两点不明白,见代码
private static Object getProxy(final Object target,final Advice advice) { //为什么这里的参数要用final修饰?
Object proxy3 = Proxy.newProxyInstance(
target.getClass().getClassLoader(),
/*new Class[]{Collection.class},*/ //这里应该是要接受数组形式的参数
target.getClass().getInterfaces(), //为什么这里却没用数组??
new InvocationHandler(){
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
/*long beginTime = System.currentTimeMillis();
Object retVal = method.invoke(target, args);
long endTime = System.currentTimeMillis();
System.out.println(method.getName() + " running time of " + (endTime - beginTime));
return retVal;*/
advice.beforeMethod(method);
Object retVal = method.invoke(target, args);
advice.afterMethod(method);
return retVal;
}
}
);
return proxy3;
}
|