2
I’ve been observing that conditional expressions in Java that are formed only by literals or constants (or operations between them) are evaluated in different ways. Therefore, the code below compiles normally:
public class Main {
public static void main(String[] args) {
if (true) {
System.out.println("teste");
}
while (true) {
System.out.println("teste");
}
}
}
However, this other section does not compile. The compiler complains of "Unreachable code" only in the part of while
, the part within the if
is also "unreachable".
public class Main {
public static void main(String[] args) {
if (false) {
System.out.println("teste");
}
while (false) {
System.out.println("teste");
}
}
}
I wonder if it is possible to make "unreachable codes" inside blocks if
as in the above example are also treated as compile-time errors. Does anyone know of any flag I can pass to the compiler for this to happen? (if this flag exists) Or a similar mechanism?