黑马程序员技术交流社区

标题: 我写的代理程序,一模一样,怎么老出bug?求大神指点 [打印本页]

作者: MichaelRodman    时间: 2014-9-19 10:39
标题: 我写的代理程序,一模一样,怎么老出bug?求大神指点
Collection proxy=(Collection)Proxy.newProxyInstance(
                                Collection.class.getClassLoader(),
                                new Class[]{Collection.class},
                                new InvocationHandler(){
                                       
                                        @Override
                                        public Object invoke(Object arg0, Method method, Object[] arg2)
                                                        throws Throwable {
                                                ArrayList target=new ArrayList();
                                               
                                                return method.invoke(target,args);
                                        }
                                       
                                });
                proxy.add("xxx");
                proxy.add("lhm");
                proxy.add("bxd");
                System.out.println(proxy.size());
错误如下:Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at FileTest$1.invoke(FileTest.java:22)
        at com.sun.proxy.$Proxy0.size(Unknown Source)
        at FileTest.main(FileTest.java:29)




作者: 何艳梅    时间: 2014-9-19 14:55
return method.invoke(target,arg2);
作者: MichaelRodman    时间: 2014-9-20 10:41
何艳梅 发表于 2014-9-19 14:55
return method.invoke(target,arg2);

嗯嗯,后来发现了。。。谢谢啊




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2