首頁 / CompScience / Programming / Languages / java / The wrapper classes cannot be used like primitives

The wrapper classes cannot be used like primitives

2009-12-08_162315

我的疑問為何不是2,答案這樣解釋:

3) Compile time error

The wrapper classes cannot be used like primitives.

Depending on your compiler you will get an error that says someting like “Error: Can’t convert java lang Integer”. Wrapper classes have similar names to primitives but all start with upper case letters.

Thus in this case we have int as a primitive and Integer as a wrapper. The objectives do not specifically mention the wrapper classes but don’t be surprised if they come up.

但是我編譯及執行的結果是2沒錯,我是直覺它可以autobox,所以不會錯,問題真是讓人費解!

Print Friendly, PDF & Email
馬上成為工作達人的Fans

About ㄚ琪

工作達人Fun Taiwan的創辦者及總編,可以在這裡更認識他。

發表迴響

你的電子郵件位址並不會被公開。 Required fields are marked *

*

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

Scroll To Top