【发布时间】:2014-06-18 00:10:42
【问题描述】:
我有一个简单的类,在它下面编译时自动装箱整数正确 但是,没有为我的布尔值做到这一点,它坚持我应该将参数更改为布尔值。我使用的是 jdk 1.8,否则编译器会抱怨整数转换。我看不到我做错了什么?所有包装类都可以开箱即用,或者我认为?
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
【问题讨论】:
-
您可能会考虑分享实际的编译器错误,而不是让我们猜测......
-
this.id = 2;行中根本没有装箱,因此您的评论“自动装箱工作”不正确。
标签: java boolean autoboxing