- public class TestShort
 
 - {
 
 - public static void main(String[] args){
 
 - short s=1;
 
 - s=s+1;
 
 - System.out.println(s);
 
 - }
 
 - }
 
  复制代码 
 
 
s=s+1这句先执行s+1然后把结果赋给s,由于1为int类型,所以s+1的返回值是int类型,类型转换可由小到大自动转,即byte->short->int->long如果反过来会丢失精度,必须进行显示类型转换,这样写“s+=1”可以,因为+=是操作符,在解析时候s+=1就等价于s = (short)(s+1),属强制转换,希望对你有帮助 
 |