3

Note my question is not regarding != but |=

A usage example is here

I assume that x |= y is the same as x = x | y but I could not find confirming documentation and wanted to be sure

Thanks

Hamy
  • 20,662
  • 15
  • 74
  • 102

4 Answers4

7

It's a bitwise "or" plus assignment, so you are quite correct in your assumption.

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
4

Yes, it's a bitwise inclusive or assignment: http://www.cafeaulait.org/course/week2/03.html

Phil C
  • 3,687
  • 4
  • 29
  • 51
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 :)

BjornS
  • 1,004
  • 8
  • 19
2

You can read Java Langauge Specification

Dennis C
  • 24,511
  • 12
  • 71
  • 99