• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

What operator is this: |= ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this in the code i'm doing maintenance:

boolean draw = false;
//some code
draw |= x.equals(a) &&(Integer.parseInt(c)>=Integer.parseInt(d));

It compiles fine... but doesn't do what it supossed to do. I already correct it, but i'm not sure what exactly is "|=" (and is not "!="). Any ideas?
 
Marshal
Posts: 64616
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A compound assignment operator with | which is the bitwise [inclusive] OR and = which is assignment.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The notation "x #= y" where # is an operator like +, -, *, /, |, & is a shorthand way of writing "x = x # y".

So, in your case: draw |= ... means: draw = draw | ...
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

'|' operator is a pipe operator and it is used to perform 'logical OR' operation. It is one of the logical operators in Java.

When used with compound statement like
x |= y it is to be read as x = x | y

Bye TC
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!