3

请注意,我的问题不是关于,!=而是|=

使用示例在这里

我认为这x |= yx = x | y但我找不到确认文件并想确定

谢谢

4

4 回答 4

7

这是一个按位“或”加赋值,所以你的假设是完全正确的。

于 2010-08-06T04:06:59.660 回答
4

是的,这是一个按位包含或分配: http: //www.cafeaulait.org/course/week2/03.html

于 2010-08-06T04:14:33.690 回答
3

More correctly, x |= y is actually computed as x = x | (y).

Here is an interesting example of why this is important.

int c = 2;
c %= c++ * ++c;

The interesting consequence here is that it would be written as

c = c % (c++ * ++c);

Java specifications tell us that the JVM will see the initial c first and store it, anything preceding it will have no effect on it, thus c++ & ++c will not actually affect the outcome of the calculation. It will always be c = 2 % which equals 2 :)

于 2010-08-06T09:44:10.367 回答
2

您可以阅读Java 语言规范

于 2010-08-06T04:10:19.277 回答