Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

bitwsie and short-circuit logical operators  RSS feed

 
Jerret Halter
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I was curious if bitwise and short-circuit logical operators have an order of procedence. For example (which came from an scjp book):



or another



Thanks in advance
[ February 09, 2006: Message edited by: Jerret Halter ]
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's Order Of Prescendence (taken from Teach Yourself Java 2 in 21 Days, pages 84-85):

. [] ()
++ -- ! ~ instanceof
new (cast)...
* / %
+ -
<< >> >>>
< > <= >=
== !=
&
^
|
&&
||
?:
= += -= *= /= %= ^=
&= |= <<= >>= >>>=

The higher on the list, the sooner it happens.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's one thing to watch out when using the | and & operators. They will evaluate your entire conditions, so be careful if you may hit a NullPointerException in the testing conditions.

Operators && and || are generally faster as they won't execute the entire set of conditions.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!