Java中,Runtime.exit(0)和System.exit(0)有什么区别?

4

Runtime.exit(0)和System.exit(0)有什么区别?

Runtime.exit(0)和System.exit(0)的区别是什么?

类似地,Runtime.gc()和System.gc()有什么区别?

Runtime.gc()和System.gc()的区别是什么?

什么时候使用哪种方法?


System.exit(n)在内部调用了Runtime.getRuntime().exit(n)gc()同理。 - roottraveller
4个回答

2

What is the difference between

Runtime.exit(0) and System.exit(0)

无。

Similarly what is the difference between

Runtime.gc() and System.gc()

没有区别。

何时使用哪个?

由于它们没有区别,所以选择纯粹是为了美观而已。


你应该至少加上一些解释。 - roottraveller

2

System.Xxxx 较为简短,直接使用 Runtime.Xxxx() 无法实现。


1

0

为什么不呢?这个观点过去是正确的,现在依然如此。但是,这里有链接:http://docs.oracle.com/javase/7/docs/api/java/lang/System.html - Dariop
是的,但在这种情况下,链接到过时的文档而不是当前的文档肯定没有好的理由。 - Michael Borgwardt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接