課程
/后端開發(fā)
/Java
/深入淺出Java多線程
老師的例子是 Thread actor = new Actor();這個地方我寫成 Actor actor = new Actor()行不行?寫成前者的好處是什么?求指點,謝謝
2016-06-23
源自:深入淺出Java多線程 2-3
正在回答
也可以用你創(chuàng)建的Actor類來實例化,就像樓上說的,用Thread類實例化等于是向上轉(zhuǎn)型,不會溢出.
寫成 Thread actor = new Actor(); ?的好處是 直接用 Thread 類對Actor的實例actor進(jìn)行向上轉(zhuǎn)型,方便后面actor調(diào)用Thread類的方法。 ?你用 Actor?actor = new Actor(); 也可以,只是后面再用到Thread的方法時,你還是要把actor轉(zhuǎn)型成Thread。
紅袖侍讀 提問者
舉報
帶你一起深入淺出多線程,掌握基礎(chǔ),展望進(jìn)階路線
3 回答Thread actor=new Thread(new Actor(),"Mr.Thread");
3 回答Thread actor=new Actor(); 這怎么理解?
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).
2 回答怎么我的不行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號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-08-04
也可以用你創(chuàng)建的Actor類來實例化,就像樓上說的,用Thread類實例化等于是向上轉(zhuǎn)型,不會溢出.
2016-06-23
寫成 Thread actor = new Actor(); ?的好處是 直接用 Thread 類對Actor的實例actor進(jìn)行向上轉(zhuǎn)型,方便后面actor調(diào)用Thread類的方法。 ?你用 Actor?actor = new Actor(); 也可以,只是后面再用到Thread的方法時,你還是要把actor轉(zhuǎn)型成Thread。