I'm just wondering how Java works when it comes to if . (Note: when I say “component” below, I mean the individual parts checked by the operator, for example a , b , c )
Which is more efficient in terms of calculations?
if (a && b && c) { do stuff }
or
if (a) { if (b) { if (c) { do stuff } } }
The reason I'm asking is because what matters is what Java does in the first version. Does he check every thing in the instruction or checks a , and if it is false , then cancel the check of the rest of the instruction?
If so, then it makes sense to put a component that is likely to fail as the first component in the instruction.
If the entire instruction is checked every time, then it makes sense to divide the components into a bunch of different operators, as in the second example.
source share