Say I have something like this in a C Code. I know you can use a #define instead, to make the compiler not compile it, but just out of curiosity I’m asking if the compiler will also figure this thing out.
I think this is even more important for Java Compiler as it does not support #define.
const int CONDITION = 0;
........
// Will the compiler compile this?
if ( CONDITION )
{
}
.......
in Java, the code inside the if won’t even be part of the compiled code. It must compile, but it won’t be written to the compiled bytecode. It actually depends on the compiler, but I don’t know of a compiler that doesn’t optimize it. the rules are defined in the JLS:
Don’t know about C.