为什么这里需要 Actor 阵容?
byte a = 0b0000_0000;
byte b = (byte) ~a;
a
是一个字节,b
是一个字节...为什么需要转换?
最佳答案
因为Java Language Specification这么说
Unary numeric promotion (§5.6.1) is performed on the operand. The type of the unary bitwise complement expression is the promoted type of the operand.
Otherwise, if the operand is of compile-time type
byte
,short
, orchar
, it is promoted to a value of typeint
by a widening primitive conversion (§5.1.2).
int
类型的值不能分配给 byte
类型的变量。
关于java - 为什么在 Java 中必须将字节上的按位运算强制转换为字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360935/