Though the logging level is set to INFO, and that at runtime the condition will never be satisfied, how am i able to prove programatically if “Hi” will not be initialized?
if(log.isDebug()){
log.debug("Hi");
}
What i mean is, since the logging level is INFO, the logger would not have a chance to print the message “Hi”, my concern is, how can i find out if the JRE or JDK will / will not take a step to prepare “Hi” even through the condition is not satisfied.
Dump the bytecodes. There will be an “ldc” opcode for the String constant. The first time that opcode is executed is when the actual String will be created. The String will then be cached in the constant pool for reuse on subsequent calls/iterations. If the “ldc” never executes the String is not created.