while之后if出现unreachable statement

1、java 中出现unreachable statement就是编译器永远不会执行该语句。

举个栗子:

 1     public static void main(String[] args) {
 2         System.out.println("check{unreachable statement}");
 3         boolean flag =false;
 4         while(true)
 5         {
 6 
 7         }
 8         if (flag)
 9         {
10         }
11     }

这种情况下,就必然会出现编译器的unreachable statement提示。

 1     public static void main(String[] args) {
 2         System.out.println("check{unreachable statement}");
 3         boolean flag =false;
 4         while(true)
 5         {
 6             break;
 7         }
 8         if (flag)
 9         {
10         }
11     }

这种情况下,编译器就不会报错;值得注意的是while循环里,填写continue,编译器同样会报错。

posted @ 2018-03-24 14:37  乐在跑途  阅读(459)  评论(0编辑  收藏  举报