JLS在这里不会“提升到更大的数据类型”,因为它不会为转移运算符执行二进制数字提升.这由
JLS, Section 15.19涵盖.
Unary numeric promotion (§5.6.1) is performed on each operand separately. (Binary numeric promotion (§5.6.2) is not performed on the operands.)
一元数字促销将字节a提升为int.文字4L没有改变,但无论如何它只需要是一个整体类型.
It is a compile-time error if the type of each of the operands of a shift operator, after unary numeric promotion, is not a primitive integral type.
然后,对于移位,仅使用至少5个有效位来移位int.
If the promoted type of the left-hand operand is int, then only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x1f (0b11111). The shift distance actually used is therefore always in the range 0 to 31, inclusive.
运算符的结果是int,而不是long,因此可以在没有编译器错误的情况下将其赋值给int.
The type of the shift expression is the promoted type of the left-hand operand.