short +=2 跟short = short +2

short a = 2;

 a = a +2  //编译失败
 a +=2		//编译成功

a = a +2 中第二个a是short类型,2常量默认是int,不能自动转换所以报错。
a +=2 中+=会默认将右边进行一个强转换, 即是a = (short)(a+2)

Guess you like

Origin blog.csdn.net/weixin_43859562/article/details/112891400