這一章的難度加上翻譯的水準使得我實在好像是在看天書啊,所以分開寫了;
首先我們來看看靜態代理:
public interface Sell //說呢,從古至今都有這么一個賣的接口,誰都可以賣東西;{ void sell(); void ad();}public class Vendor implements Sell { //賣主,小販實現了他的賣法還有廣告; public void sell() { System.out.以上就是靜態代理的內容了; 就好像供貨商,代理商之間的關系;賣不賣給你代理是可以決定的;下面的代碼改動會使得方法的動態修改變得明朗
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // System.out.println("before"); try { Class c = Class.forName("Proxy.Sell"); Method method1 = c.getMethod("sell", null); Class c2 = Class.forName("Proxy.Sell"); Method method2 = c2.getMethod("ad",null); if (method.equals(method1)) { System.out.println("處理器正在調用sell方法"); } if (method.equals(method2)) { System.out.println("處理器正在調用ad方法"); } }catch (Exception e) { System.out.println(e); } Object result = method.invoke(obj, args); // System.out.println("after"); return result; }ouput:處理器正在調用sell方法In sell method處理器正在調用ad方法ad method還是蠻清楚的吧;
新聞熱點
疑難解答