Car car = new Car(); Class<?> cls = car.getClass(); InvocationHandler timeHandler = new TimeHandler(car); InvocationHandler logHandler = new LogHandler(car); Moveable moveable = (Moveable) Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), timeHandler); Moveable m = (Moveable)Proxy.newProxyInstance(moveable.getClass().getClassLoader(), cls.getInterfaces(), logHandler); m.move();timeHandler和logHandler 是兩個調用處理器,各自重寫的invoke方法的業務邏輯不同。Car類實現了Moveable接口,這接口里只有一個move方法,現在怎么才能讓move在執行時能夠新增timeHandler 和logHandler 的方法呢?我現在寫的這樣不行
添加回答
舉報
0/150
提交
取消