黑马程序员技术交流社区

标题: 动态代理类 [打印本页]

作者: lyssenlove    时间: 2014-7-12 13:49
标题: 动态代理类
Proxy.newProxyInstance(Collection.class.getClassLoader(),
                                                                new Class[]{Collection.class},
                                                                new InvocationHandler(){

                                                                        @Override
                                                                        public Object invoke(Object proxy,
                                                                                        Method method, Object[] args)
                                                                                        throws Throwable {
                                                                                // TODO Auto-generated method stub
                                                                                ArrayList arrayList = new ArrayList();
                                                                                long begin = System.currentTimeMillis();
                                                                                Object obj = method.invoke(arrayList, args);
                                                                                long end = System.currentTimeMillis();
                                                                                method.invoke(obj, args)
                                                                                return obj;
                                                                        }
                       
                                                                               
                       
                                                                });

invoke里面的各个参数代表什么啊,对整个函数方法来说怎么理解啊。。
作者: 谭荣强    时间: 2014-7-12 18:35
object:代表你调用的动态代理对象
Method:调用代理的方法的Method对象
args;方法里的参数

这个方法属于代理,它的作用就是去调用目标方法完成实际操作,也就是代理不参与操作(除了系统功能),它负责转移给目标类,转移的功能就是invoke.
作者: alive    时间: 2014-7-12 19:08
object     目标类
Method:  目标类方法
args:     目标类方法里的参数
       个人理解 !




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