zoukankan      html  css  js  c++  java
  • 代理

    静态代理

    x和a都有一样的接口,x传入了a,x做事其实还是调用自己内部的a
    缺点:代理类和委托类实现了相同的接口,代理类通过委托类实现了相同的方法。所以代理对象只服务于一种类型的对象。

    动态代理

    局限性:被代理类必须实现接口,只能当作父类对象

    步骤:Proxy的静态方法+Invocation接口,实现invoke方法

    arsg是用到原来的参数,但是现在还没搞懂返回值是干嘛的

    class MyInvoHandler implements InvocationHandler {
        Object target;
    
        public MyInvoHandler(Object target) {
            this.target = target;
        }
        public void myMethod(){
            System.out.println("11");
        }
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    
            System.out.println("先洗手");
            method.invoke(target,args);
            return  "这是什么?";
        }
    }
    class Test1{
        public static void main(String[] args) {
            Stu stu = new Stu();
            MyInvoHandler myInvoHandler = new MyInvoHandler(stu);
            Human stu1 = (Human) Proxy.newProxyInstance(stu.getClass().getClassLoader(),
                    stu.getClass().getInterfaces(),
                    myInvoHandler);
    
        }
    }
    

    cglib

  • 相关阅读:
    201141 live the lie until the lie becomes your life
    my php & mysql FAQ
    suger日料财务
    python 应用thrift thrift的监控fb303
    cherryPy学习
    my linux FAQ
    Javascript无阻塞加载方法
    设计模式学习笔记之组合模式模式
    【转】cookie
    C# 多线程
  • 原文地址:https://www.cnblogs.com/purexww/p/15254231.html
Copyright © 2011-2022 走看看