本帖最后由 heheka123 于 2014-4-23 10:49 编辑  
- class Demo12
 
 - {
 
 -         public static void main(String[] args) throws Exception {
 
  
-                 Collection myProxy = (Collection)Proxy.newProxyInstance(
 
 -                         Collection.class.getClassLoader(),
 
 -                         new Class[]{Collection.class}, 
 
 -                         new InvocationHandler() {
 
 -                                 private ArrayList target = new ArrayList();        
 
 -                                 @Override
 
 -                                 public Object invoke(Object proxy, Method method, Object[] args)
 
 -                                                 throws Throwable {
 
 -   //问题在这,我想知道第一个参数Object proxy 是干嘛用的啊,在这个里面都没有上啊
 
 -   //还有就是 return  retVal  这个返回的结果是去哪了,干嘛的呢   我return null;就报错了
 
 -                                         long beginTime = System.currentTimeMillis();
 
 -                                         //代理调用的对象
 
 -                                         Object retVal = method.invoke(target,args);
 
 -                                         //结束时间
 
 -                                         long endTime = System.currentTimeMillis();
 
 -                                         System.out.println("运行时间:"+(endTime-beginTime));
 
 -                                         return retVal;
 
 -                                         //return null;
 
 -                                 }
 
 -                         });
 
 -                 myProxy.add("xxx");
 
 -                 myProxy.add("yyy");
 
 -                 myProxy.add("zzz");
 
 -                 myProxy.add("www");
 
 -                 System.out.println("List的长度为:"+myProxy.size());
 
 -         }
 
 - }
 
  复制代码 
 |