问答详情
源自:2-3 了解 JDK 动态代理

发一下作业

发一下作业

提问者:yyyyy66 2018-03-31 17:51

个回答

  • 大橙砸
    2018-08-31 11:16:11

    public static void main(String[] args) {
            Car car=new Car();
            InvocationHandler h=new TimeHandler(car);
            Class<?> cls=car.getClass();
            /*
             * #参数
             * loader 类加载你
             * interfaces 实现接口
             * h InvovationHandler
             * 
             * 用newProxyInstance()动态创建一个代理类
            */
            Moveable m=(Moveable)Proxy.newProxyInstance(cls.getClassLoader(), 
                    cls.getInterfaces(), h);
            
            InvocationHandler h2=new LogHandler(m);
            Class<?> clh=m.getClass();
            Moveable m2=(Moveable)Proxy.newProxyInstance(clh.getClassLoader(), 
                    clh.getInterfaces(), h2);
            m2.move();
        }


  • 总该到我了吧
    2018-08-25 14:39:00

    Car car = Car();
    InvocationHandler h = new jdkProxy(car);
    Class<?> cls = car.getClass();
    IMoveable proxycar = (IMoveable) Proxy.(cls.getClassLoader()cls.getInterfaces()h);
     proxycar.move()Class<?> cls2 = proxycar.getClass();
     IMoveable proxycar2 = (IMoveable) Proxy.(cls2.getClassLoader(),cls2.getInterfaces(),new jdkProxy2(proxycar));
      proxycar2.move();


  • 慕哥6772552
    2018-04-11 21:48:09

    Car car = Car()InvocationHandler h = jdkProxy(car)Class<?> cls = car.getClass()IMoveable proxycar = (IMoveable) Proxy.(cls.getClassLoader()cls.getInterfaces()h)proxycar.move()Class<?> cls2 = proxycar.getClass()IMoveable proxycar2 = (IMoveable) Proxy.(cls2.getClassLoader()cls2.getInterfaces()jdkProxy2(proxycar))proxycar2.move()