• Post Reply Bookmark Topic Watch Topic
  • New Topic

|| versus |  RSS feed

 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok as an old c developer to me | only means bitwise or, so...

my java certified buddies assured me the diff between || and | was that:
with || the chain of evaluations would stop at the very first true one but with | it would evaluate both sides no matter if the left is already true,
and that was the intended difference between the two operators. The sun training documentation only refers to | as the bitwise inclusive or operator.

Are my java certified friends correct and that the continue evaluating action was suns intentional difference, or am i correct that it is just a side effect?

if you could provide some links with proof of either side that would be fantastic
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are right. The Java Language Specification -- section 15.24 for example.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh thank you that was the document i was after, java distinguishes between the
15.22.1 Integer Bitwise Operators &, ^, and |
and the
15.22.2 Boolean Logical Operators &, ^, and |

and under
15.24 Conditional-Or Operator || it says
Thus, || computes the same result as | on boolean or Boolean operands. It differs only in that the right-hand operand expression is evaluated conditionally rather than always.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!