1 分为jdk自带代理 2 实现接口 InvocationHandler ,用反射调用方法 3 获取代理类:Proxy.newProxyInstance(cls.getClassLoader(),cls.getInterfaces(), new TestProxy(obj)); 4 5 实例: 6 public interface ReadFile { 7 public void read(); 8 } 9 10 public class Boss implements ReadFile { 11 @Override 12 public void read() { 13 System.out.println("I'm reading files."); 14 } 15 } 16 17 public class Secretary implements InvocationHandler { 18 private Object object; 19 public Secretary(Object object) { 20 this.object = object; 21 } 22 @Override 23 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 24