黑马程序员技术交流社区

标题: 问个代理问题 [打印本页]

作者: 谭荣强    时间: 2014-6-11 23:36
标题: 问个代理问题
new ProxyInstance()返回值是什么?为什么ArrayList的代理类返回值写ArrayLsit不行,写List就可以
List proxydemo = (List)Proxy.newProxyInstance(
                                ArrayList.class.getClassLoader(),
                                ArrayList.class.getInterfaces(),
                                new InvocationHandler() {                                         
                                        public Object invoke(Object proxy, Method method, Object[] args)
                                                        throws Throwable {                                                 
                                                ArrayList list = new ArrayList();
                                                Object retvalue = method.invoke(list, args);                                         
                                                return retvalue;
                                        }
                                }
                                );




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