结论
+= 操作符会进行隐式自动类型转换而+不包含
示例
示例1:
示例2:
public class Test {public void test() {byte a = 127;byte b = 127;a += b; //可正常运行,+=包含隐式自动类型转换a = a + b; //此行会报错,因为+运算不含隐式转换a = (byte) (a + b); //添加强制类型转换后可正常运行short s1 = 1;s1 += 1; //可正常运行,+=包含隐式自动类型转换s1 = s1 + 1; //此行会报错,因为+运算不含隐式转换s1 = (short) (s1 + 1); //添加强制类型转换后可正常运行}}