如果 short
在算术运算中自动升级为 int
,那么为什么是:
short thirty = 10 * 3;
对 short
变量 thirty
的合法赋值?
反过来,这个:
short ten = 10;
short three = 3;
short thirty = ten * three; // DOES NOT COMPILE AS EXPECTED
还有这个:
int ten = 10;
int three = 3;
short thirty = ten * three; // DOES NOT COMPILE AS EXPECTED
不能编译,因为如果没有按照预期进行强制转换,则不允许将 int
值分配给 short
。
关于数字字面值有什么特别的吗?