Why does a Java Compiler not produce an unreachable statement error for an unreachable then statement?

后端 未结 5 994
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 17:33

If I try to compile

for(;;)
{

}
System.out.println(\"End\");

The Java compiler produces an error saying Unreachable statement

5条回答
  •  长情又很酷
    2020-12-29 18:14

    As explained in my answer to a similar question, the specific construct if(compile-time-false) is exempt from the unreachability rules as an explicit backdoor. In this case, the compiler treats your break as reachable because of that.

提交回复
热议问题