short相加自动转化为INT

精度小于int的数值运算的时候都回被自动转换为int后进行计算

所以,下面的代码会报编译错误

short s1 = 1;
short s2 = 1;
s1= (s1+s2);

必须改成:

short s1 = 1;
short s2 = 1;
s1= (short)(s1+s2);

但是,s1+=4;是正确的

原文地址:https://www.cnblogs.com/qiu18359243869/p/12499950.html