Questions tagged «unreachable-statement»

8
Java为什么会有“无法到达的语句”编译器错误?
我经常在调试程序时发现在代码块内插入return语句很方便(尽管可能是不好的做法)。我可能会在Java中尝试类似的方法。 class Test { public static void main(String args[]) { System.out.println("hello world"); return; System.out.println("i think this line might cause a problem"); } } 当然,这会产生编译器错误。 Test.java:7:无法访问的语句 我能理解为什么警告是合理的,因为有未使用的代码是不好的做法。但是我不明白为什么这需要产生一个错误。 这只是Java试图成为一个保姆,还是有充分的理由使它成为编译器错误?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.