2

I was looking trough some coding to extend my knowledge in Java and I came across the following line of code which I do not understand and googling returns nothing on the matter.

int metadata;
int facing;
metadata |= facing;

what does the |= mean/do is there documentation on this (Or more to the point what is this operation called)

JohnM
  • 105
  • 10

3 Answers3

3

"|" is boolean logical OR and placing the operand before "=" works pretty much the same as expressions like a += b (which means a = a + b).

So basically, a |= b is the same as a = a | b

List of all Java operands can be found here.

Smajl
  • 7,555
  • 29
  • 108
  • 179
2

It is the same as

metadata = metadata | facing;

More on Java's operators here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Kninnug
  • 7,992
  • 1
  • 30
  • 42
0

This is shorthand for

metadata = metadata | facing; 
CodeBlue
  • 14,631
  • 33
  • 94
  • 132