//定义一个ArrayList类型的常量
final ArrayList target = new ArrayList();
List proxy = (List)Proxy.newProxyInstance(
List.class.getClassLoader(),//得到类加载器
ArrayList.class.getInterfaces(),
new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
long beginTime = System.currentTimeMillis();//得到当前时间
Thread.sleep(10);
Object reVal = method.invoke(target, args);
long endTime = System.currentTimeMillis();//得到当前时间
//输出
System.out.println(method.getName()+" runing time is "+(endTime-beginTime));
return reVal;
}
});
代理类是怎么回事,能把上面的代码解释下吗?
|