为什么编译器在编译时识别while(true)而不是if(true)

时间:2015-06-08 14:29:21

标签: java oop inheritance if-statement while-loop

以下代码给出了编译时错误 - 无法访问的语句

while(true)
  return;
return;  // Unreachable statement

但是,以下代码不会出现任何错误:

if(true)
   return;
return;  // Reachable, No Error

我无法理解为什么编译器会识别出在while的情况下,永远不会达到第二个return语句,但在if的情况下它不会识别相同的语句?

0 个答案:

没有答案