发一下作业
发一下作业
发一下作业
2018-03-31
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(); }
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();
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()
举报