java中+=运算符问题
public class test{
public static void main(String[] args){
byte a=5;
a=a+5;
byte b=5;
b+=5;
}
}
这段代码中,a=a+5因为表达式a+5是int类型,赋值给byte类型a而错误,下面的b+=5为什么不会报错呢,+=的运行机制究竟是怎么样的?求各位解惑!
public static void main(String[] args){
byte a=5;
a=a+5;
byte b=5;
b+=5;
}
}
这段代码中,a=a+5因为表达式a+5是int类型,赋值给byte类型a而错误,下面的b+=5为什么不会报错呢,+=的运行机制究竟是怎么样的?求各位解惑!
...全文


Java SE

