A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 盖保宁 黑马帝   /  2011-10-4 09:04  /  1537 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

Collection proxy = (Collection)Proxy.newProxyInstance(
                            ArrayList.class.getClassLoader(),
                            new Class[]{Collection.class, Cloneable.class,Iterable.class,RandomAccess.class,List.class},
                            new MyInvocationHandler()
                            );


这样代理虽然 proxy 有了List接口的.add(index, object)方法但是  因为Collection proxy = (Collection)P。。。。。
儿Collection接口没有.add(index, object)只有.add(object),所以proxy.add(1,"a");会编译不通过怎么办  我要用proxy.add(1,"a");

评分

参与人数 1技术分 +1 收起 理由
admin + 1

查看全部评分

2 个回复

倒序浏览
黑马网友  发表于 2011-10-4 09:52:53
沙发
你扔个list接口就可以了
回复 使用道具 举报
黑马网友  发表于 2011-10-4 10:03:06
藤椅
是的,换成List接口就OK了,把Collection.class去掉
List proxyList=(List) Proxy.newProxyInstance(
                List.class.getClassLoader(),
               new Class[]{List.class},
               new InvocationHandler() {
               public Object invoke(Object proxy, Method method, Object[] args)throws Throwable {
                        // TODO Auto-generated method stub
                        return null;
                        }
                });

评分

参与人数 1技术分 +1 收起 理由
admin + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马