The &&
operator (and also ||
) is a short-circuit operator in Java.
That means that if a
is false
, Java doesn't evaluate b
, c
, d
etc., because it already knows the whole expression a && b && c && d && e && f && g
is going to be false
.
So there is nothing to be gained to write your if
as a series of nested if
statements.
The only good way to optimize for performance is by measuring the performance of a program using a profiler, determining where the actual performance bottleneck is, and trying to improve that part of the code. Optimizing by inspecting code and guessing, and then applying micro-optimizations, is usually not an effective way of optimizing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…