- class Test9{
-
- public static void main(String[] args) throws Exception {
- final ArrayList target = new ArrayList();
- List list = (List)Proxy.newProxyInstance(
- ArrayList.class.getClassLoader(),
- target.getInterfaces(),
- new InvocationHandler(){
- public Object invoke(Object obj,Method method,Object[] args) throws Throwable{
- Long beginTime = System.currentTimeMillis();
- Thread.sleep(5);
- Object result = method.invoke(target,args);
- Long endTime = System.currentTimeMillis();
- System.out.println(method<div class="blockcode"><blockquote>.getNa
复制代码
me()+"runtime is:"+(endTime-beginTime));
return result;
}});
list.add("youxiang");
}
}
- List list = (List)Proxy.newProxyInstance(
- ArrayList.class.getClassLoader(),
- ArrayList.class.getInterfaces(),
复制代码
这里不对,ArrayList.class.getInterfaces(),,楼主可以创建个对象穿进去,用对象.getInterfaces(),就可以了 |