課程
/后端開(kāi)發(fā)
/Java
/深入淺出Java多線程
老師的例子是 Thread actor = new Actor();這個(gè)地方我寫成 Actor actor = new Actor()行不行?寫成前者的好處是什么?求指點(diǎn),謝謝
2016-06-23
源自:深入淺出Java多線程 2-3
正在回答
也可以用你創(chuàng)建的Actor類來(lái)實(shí)例化,就像樓上說(shuō)的,用Thread類實(shí)例化等于是向上轉(zhuǎn)型,不會(huì)溢出.
寫成 Thread actor = new Actor(); ?的好處是 直接用 Thread 類對(duì)Actor的實(shí)例actor進(jìn)行向上轉(zhuǎn)型,方便后面actor調(diào)用Thread類的方法。 ?你用 Actor?actor = new Actor(); 也可以,只是后面再用到Thread的方法時(shí),你還是要把a(bǔ)ctor轉(zhuǎn)型成Thread。
紅袖侍讀 提問(wèn)者
舉報(bào)
帶你一起深入淺出多線程,掌握基礎(chǔ),展望進(jìn)階路線
3 回答Thread actor=new Actor(); 這怎么理解?
3 回答Thread actor=new Thread(new Actor(),"Mr.Thread");
2 回答怎么我的不行Actor報(bào)錯(cuò)
2 回答No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).
4 回答No enclosing instance of type Actor is accessible. Must qualify the allocation with an enclosing instance of type Actor (e.g. x.new A() where x is an instance of Actor).
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-08-04
也可以用你創(chuàng)建的Actor類來(lái)實(shí)例化,就像樓上說(shuō)的,用Thread類實(shí)例化等于是向上轉(zhuǎn)型,不會(huì)溢出.
2016-06-23
寫成 Thread actor = new Actor(); ?的好處是 直接用 Thread 類對(duì)Actor的實(shí)例actor進(jìn)行向上轉(zhuǎn)型,方便后面actor調(diào)用Thread類的方法。 ?你用 Actor?actor = new Actor(); 也可以,只是后面再用到Thread的方法時(shí),你還是要把a(bǔ)ctor轉(zhuǎn)型成Thread。