相关疑难解决方法(0)

我们何时应该在Java中调用System.exit

在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)

文件说:"这种方法永远不会正常返回." 这是什么意思?

java exit

191
推荐指数
8
解决办法
34万
查看次数

如何从程序中退出Java应用程序

使用代码退出Java应用程序的最佳方法是什么?

java

142
推荐指数
4
解决办法
35万
查看次数

为什么即使在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 ×3

exit ×1

return ×1