我有一个简单的类下面编写自动包装整数正确 但是,无法为我的布尔它坚持我应该改变参数为布尔值。我使用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