在第二章jdk動(dòng)態(tài)代理中 要實(shí)現(xiàn)多事物的處理處理,測(cè)試類要如何編寫?
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();
//上面的只是實(shí)現(xiàn)了時(shí)間的處理? 如何也實(shí)現(xiàn) 日志處理?
InvocationHandler handlerLog = new LogHandler(handlerTime);
Moveable mLog = (Moveable) Proxy.newProxyInstance(classCar.getClassLoader(),classCar.getInterfaces(),handlerLog);
2019-07-14
mTime是對(duì)car的時(shí)間代理對(duì)象,再生成mLog即mTime的日志代理對(duì)象即可。