The following code is not compiled in Java:
public class Unreachabletest {public static void main (string[] args) {while (true) {}system.out.println ("aaaaaa");}}
This code does not seem to have any syntax errors, but it is very obvious that this code is not meant to be, AAAAA will never output,
Java, however, differs from the C language in that Java considers this code to be an unreachable language error and cannot be compiled at all.
If you run this code, the following conditions will occur,
This is not to say that the structure of your while (true) is wrong, or that there is no code after the while (true), and that there is no break in the structure, and there is no code behind it, such as:
public class Unreachabletest {public static void main (string[] args) {when (true) {break;} System.out.println ("aaaaaa");}}
Is the correct code, running the result is aaaaaa, or is also the correct code, although this program never end:
public class Unreachabletest {public static void main (string[] args) {while (true) {}}}
So, when you write a program that needs to use a dead loop structure, if Eclipse makes that kind of simplified, saying that you're wrong about the code behind the while, you should understand what's going on, rather than just follow the advice and delete it.
"Java" Unreachable Code compilation exception