Say I have below lines any in a Java class,
System.out.println("start");
if(true)//The compiler will give compile time error if I uncomment this.
throw new RuntimeException();
System.out.println("end");
The unreachable code error message will appear if the if(true)
is commented. Why Don't the compiler know that the line under if(true)
will always be executed?
Is the Java compiler is designed to work like this or is it a limitation?