在第二章jdk動態代理中 要實現多事物的處理處理,測試類要如何編寫?
CarSimp car = new CarSimp();
InvocationHandler handlerTime = new TimeHandler(car);
Class classCar = car.getClass();
Moveable mTime = (Moveable) Proxy.newProxyInstance(classCar.getClassLoader(), classCar.getInterfaces(), handlerTime);
mTime.move();
//上面的只是實現了時間的處理? 如何也實現 日志處理?
InvocationHandler handlerLog = new LogHandler(handlerTime);
Moveable mLog = (Moveable) Proxy.newProxyInstance(classCar.getClassLoader(),classCar.getInterfaces(),handlerLog);
2019-07-14
mTime是對car的時間代理對象,再生成mLog即mTime的日志代理對象即可。