在Java中进行基本类型的类型转换

short a = 1;

short b = 2;

那么 a+b 是什么类型?

答案:int型;

   a,b相加前先自动转换成了int,相加后当然是int。在编译器能看到Type mismatch: cannot convert from int to short

猜你喜欢

转载自www.cnblogs.com/ZoeyCLM/p/10356344.html