This:
if (var) {
var = false;
}
Versus this:
var = false;
Is there a speed difference?
The "speed difference," if any, will depend entirely on the JVM. Any decent compiler should be able to optimize away the test, at which point the two are identical.
Exception: If var
is declared volatile
the conditional version will always be slower.
In any case, if performance is critical, the best option is to measure it under expected conditions (machine, system, JVM, typical load, etc.).