JDK Proxy(代理對象): Proxy.newProxyInstance 方法的三個參數
創建代理對象 增強 person對象 使用代理對象代替person 去執行 doCourt方法
參數1 類加載器
ClassLoader classLoader = person.getClass().getClassLoader();
參數2 被代理對象實現的所有的接口的字節碼數組
Class[] interfaces =person.getClass().getInterfaces();// {Court.class , ... , ...};
Class[] interfaces={Court.class};
參數3 執行處理器 用於定義方法的增強規則(加強后的方法)
InvocationHandler handler =new InvocationHandler(){}
當代理對象調用了接口中的任何一個方法 都會將該方法以method對象的形式傳入 invoke方法
1. proxy 代理對象 2.method 被代理對象的方法 3.args 被代理對象 方法被調用時 傳入的實參 數組 4.return null;