zoukankan      html  css  js  c++  java
  • java动态代理

    @Test
        public void test(){
            
            //new UserImpl();
        /*    ProxyT  proxy=new ProxyT(new UserImpl());
            proxy.add();
            proxy.update();*/
            final User user=new UserImpl();
            User userProxy=(User) Proxy.newProxyInstance(user.getClass().getClassLoader(), new Class[]{User.class}, new InvocationHandler(){
                /**
                 * 参数
                 * ClassLoader loader:被代理的类加载器
                 * Class<?>[] interfaces:被代理类的接口,注意这里的数组一定是接口类,否则出错
                 * InvocationHandler h:将具体调用代理对象时产生的行为
                 */
                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                    /**
                     * proxy:
                     * method:代理类正在调用的方法,该处是add
                     * args:add方法所传入的参数
                     */
                    // TODO Auto-generated method stub
                    System.out.println(method);
                    System.out.println("hehehehehhehe");
                    //method.invoke(user, args);
                    return 0;
                }
                
            });
            userProxy.add();
        }

  • 相关阅读:
    Spring Boot @DeleteMapping(转)
    白天和夜晚分类
    使用HSV色彩空间遮罩绿色区域
    HSV转换
    HSV 和 HLS颜色空间
    python 处理图像出现The lower bounary is neither an array of the same size and same type as src, nor a scalar in function inRange
    读取图片上一点的像素
    python 实现A*算法
    uda 4.C++面向对象编程
    uda 3.C++二维向量
  • 原文地址:https://www.cnblogs.com/liuquande/p/3804237.html
Copyright © 2011-2022 走看看