相关疑难解决方法(0)

为什么即使在System.exit(0)之后也需要返回;

考虑这个功能:

public boolean foo(){
   System.exit(1);
   //The lines beyond this will not be read
   int bar = 1;                  //L1
   //But the return statement is required for syntactically correct code
   return false;                 //L2

   //error here for unreachable code
   //int unreachable = 3;        //L3

}
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么L1和L2明显无法访问不会发出警告但L3会发出警告.

java return

29
推荐指数
4
解决办法
7648
查看次数

标签 统计

java ×1

return ×1