在Java中,System.exit(0)以下代码有或没有区别?
public class TestExit
{
public static void main(String[] args)
{
System.out.println("hello world");
System.exit(0); // is it necessary? And when it must be called?
}
}
Run Code Online (Sandbox Code Playgroud)
该文件说:"这种方法永远不会正常返回." 这是什么意思?
考虑这个功能:
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会发出警告.