• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

What operator is this: |= ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80871
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic