I\'d like to know some cases in Java (or more generally:
in programming) when it is preferred in boolean expressions to use the unconditional AND
(&>
If the expression are trivial, you may get a micro-optimisation by using &
or |
in that you are preventing a branch. ie.
if(a && b) { }
if(!(a || b)) { }
is the same as
if (a) if (b) { }
if (!a) if (!b) { }
which has two places a branch can occur.
However using an unconditional &
or |
, there can be only one branch.
Whetehr this helps or not is highly dependant on what the code is doing.
If you use this, I sugegst commenting it to make it very clear why it has been done.