我有一個簡單的類下面編寫自動包裝整數正確 但是,無法爲我的布爾它堅持我應該改變參數爲布爾值。我使用jdk 1.8,否則編譯器會抱怨Integer轉換。我看不到我做錯了什麼?所有包裝類都可以自動包裝,或者我想過?自動裝箱不適用於布爾
public class MsgLog<Boolean,String> {
private boolean sentOk ;
private Integer id ;
private int id2 ;
public boolean isSentOk() {
return sentOk;
}
public String getTheMsg() {
return theMsg;
}
private String theMsg ;
private MsgLog(Boolean sentOkp, String theMsg)
{
this.sentOk = sentOkp ; // compile error - autoboxing not working
this.theMsg = theMsg ;
this.id = 2; // autoboxing working
this.id2 = (new Integer(7)) ; // autoboxing working the other way around as well
}
}
是不是自動裝箱是一種雙向過程?
Compile error on jdk 8 (javac 1.8.0_25)
Multiple markers at this line
- Duplicate type parameter String
- The type parameter String is hiding the type String
- The type parameter Boolean is hiding the type
Boolean
你可能會考慮分享實際的編譯器錯誤,而不是讓我們猜... – evanchooly
有沒有拳擊的一切會在行'this.id = 2;'這樣你的評論「autoboxing工作」是不正確的。 – Jesper