本帖最后由 Inspur 于 2013-9-20 11:42 编辑
Collection proxy3 = (Collection)Proxy.newProxyInstance(
Collection.class.getClassLoader(),
new Class[]{Collection.class},
new InvocationHandler() {
// 指定目标
ArrayList target = new ArrayList();
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
long beginTime = System.currentTimeMillis();
method.invoke(target, args);
long endTime = System.currentTimeMillis();
System.out.println("运行时间为:"+(endTime - beginTime));
return method.invoke(target, args);
}
});
proxy3.add("12");
proxy3.add("12");
proxy3.add("12");
System.out.println("长度是:"+proxy3.size());
张孝祥老师课上打印的是3,我的怎么打印出来是6,求高手讲解一下?
|