1 package com.bjsxt.proxy.dymanic; 2 3 import java.lang.reflect.Proxy; 4 5 /** 6 * 动态代理测试 7 * @author zht 8 * @date 2017年9月26日 下午12:27:02 9 * @version 1.0 10 * @since 11 * @return 12 */ 13 public class Client { 14 15 public static void main(String[] args) throws Exception { 16 17 Iopreation io = new Operation1Impl(); 18 19 Class<?>[] interfaces = io.getClass().getInterfaces(); 20 21 Iopreation newProxyInstance = (Iopreation)Proxy.newProxyInstance(Iopreation.class.getClassLoader(), io.getClass().getInterfaces(), new LogInvocationHandler(io)); 22 23 System.out.println(newProxyInstance.getClass().getName()); 24 25 newProxyInstance.drive("奔驰"); 26 newProxyInstance.sayHello(); 27 } 28 29 }
Vi
1 package com.bjsxt.proxy.dymanic; 2 3 import java.lang.reflect.Proxy; 4 5 /** 6 * 动态代理测试 7 * @author zht 8 * @date 2017年9月26日 下午12:27:02 9 * @version 1.0 10 * @since 11 * @return 12 */ 13 public class Client { 14 15 public static void main(String[] args) throws Exception { 16 17 Iopreation io = new Operation1Impl(); 18 19 Class<?>[] interfaces = io.getClass().getInterfaces(); 20 21 Iopreation newProxyInstance = (Iopreation)Proxy.newProxyInstance(Iopreation.class.getClassLoader(), io.getClass().getInterfaces(), new LogInvocationHandler(io)); 22 23 System.out.println(newProxyInstance.getClass().getName()); 24 25 newProxyInstance.drive("奔驰"); 26 newProxyInstance.sayHello(); 27 } 28 29 }
ew Code
1 package com.bjsxt.proxy.dymanic; 2 3 import java.lang.reflect.Proxy; 4 5 /** 6 * 动态代理测试 7 * @author zht 8 * @date 2017年9月26日 下午12:27:02 9 * @version 1.0 10 * @since 11 * @return 12 */ 13 public class Client { 14 15 public static void main(String[] args) throws Exception { 16 17 Iopreation io = new Operation1Impl(); 18 19 Class<?>[] interfaces = io.getClass().getInterfaces(); 20 21 Iopreation newProxyInstance = (Iopreation)Proxy.newProxyInstance(Iopreation.class.getClassLoader(), io.getClass().getInterfaces(), new LogInvocationHandler(io)); 22 23 System.out.println(newProxyInstance.getClass().getName()); 24 25 newProxyInstance.drive("奔驰"); 26 newProxyInstance.sayHello(); 27 } 28 29 }
时间: 2024-10-09 15:38:49