第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

關(guān)于作業(yè)的問題

關(guān)于作業(yè)的代碼實(shí)現(xiàn): InvocationHandler logh=new LogHandler(m); Class

cls2=m.getClass(); Moveable m2=(Moveable)Proxy.newProxyInstance(cls2.getClassLoader(),cls2.getInterfaces(),logh); m2.move(); 請問一下,以上實(shí)現(xiàn)方式有啥問題,為什么會報(bào)錯(cuò)?

正在回答

5 回答

System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles",?"true");
Subject?subject?=?(Subject)?Proxy.newProxyInstance(Client.class.getClassLoader(),new?Class[]{Subject.class},new?JdkProxySubject(new?RealSubject()));
subject.hello();
MathSubject?mathSubject?=?new?MathSubject();
InvocationHandler?mathHandler=?new?ProxySubject(mathSubject);
Class<?>?cls?=?mathSubject.getClass();
Subject?mathSubjectResult?=?(Subject)?Proxy.newProxyInstance(Client.class.getClassLoader(),?cls.getInterfaces(),?mathHandler);

InvocationHandler?logmathHandler=?new?LogProxySubject(mathSubjectResult);

Subject??mathResult?=?(Subject)?Proxy.newProxyInstance(Client.class.getClassLoader(),?cls.getInterfaces(),?logmathHandler);

mathResult.hello("wahahaha");
mathResult.request();

// 根據(jù)資料,添加了LogProxySubject, ProxySubjec , 替換了JdkProxySubject中的Class換為Interface 接口類Subject,這樣就好了。

0 回復(fù) 有任何疑惑可以回復(fù)我~

代理類實(shí)現(xiàn)的都是moveable接口,所以Class<?> cls = Car.getClass()這一行代碼不用更改,刪掉

Class?cls2=m.getClass();類加載器和接口換回cls就好。


0 回復(fù) 有任何疑惑可以回復(fù)我~

JDK 動(dòng)態(tài)代理作業(yè)可以參考這個(gè)

https://github.com/imooc-java/proxy/blob/master/src/test/java/com/imooc/jdkproxy/HandlerTest.java

1 回復(fù) 有任何疑惑可以回復(fù)我~

有什么錯(cuò)誤,你貼出來塞

0 回復(fù) 有任何疑惑可以回復(fù)我~

第二行應(yīng)該改成 Class<?> clsw = m.getClass();

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

關(guān)于作業(yè)的問題

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號