A constant false value used in an if statement will trivially be optimized away in case of any non-toy JIT compiler.
A constant false value used in an if statement will trivially be optimized away in case of any non-toy JIT compiler.
The javadoc for slf4j's Logger.debug implies that the JIT cannot be relied on for this:
http://slf4j.org/apidocs/org/slf4j/Logger.html#debug(java.la......)
"This form avoids superfluous string concatenation when the logger is disabled for the DEBUG level"
I think that means if you call Logger.debug("a"+"b"), the string concatenation happens even if DEBUG logging is disabled. But maybe JITs have improved since that javadoc was written, or the author was not aware of how smart JITs are.
I would be curious to know if there is a JIT expert who could weigh in on this question.
It's one of the simplest and most commonly implemented peephole optimisations - perl has handled it for as long as I can remember, I'm pretty sure cpython does, etc. etc.