Are the conditional statements if (true) and if (false) evaluated at compile time in java?
The following code compiles successfully:
int x;
if(true)
x=3;
System.out.println(x);
Does this mean that the if condition is evaluated at compile time? If so, why doesn't the following code throw an Unreachable Statement error?
if(true)
return;
return; //No error
Who cares?
Edit: Please note that my query is different from the fact that I am not comparing "if" with "while". Rather, I am comparing the same if (true) statement in two different situations, in the first it is evaluated at compile time, and in the second case it is evaluated at runtime.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: