【发布时间】:2014-07-08 09:37:46
【问题描述】:
我有一个字节变量
byte A;
和 setters-getters 方法
public void setA(byte A) throws NumberBelowEqualZeroException{
if(A > 0)
this.hoursPerWeek = hoursPerWeek;
throw new NumberBelowEqualZeroException();
}
public byte getWorkingHoursPerWeek(){
return hoursPerWeek;
}
当我尝试在 main 中设置变量时
AClass.setA(0);
NetBeans 抱怨消息不兼容的类型。从 int 到 byte 的可能有损转换。以上都不是int。我无法理解发生了什么。我应该转换像byte A = new Byte(A) 这样的字节类型吗?感谢您的帮助。
【问题讨论】:
标签: java byte type-conversion