What is an appropriate way to programmatically exit an application?

后端 未结 6 1566
慢半拍i
慢半拍i 2021-01-26 17:57

I am evaluating user inputs as commands for my application. If the user presses Q, or q, and then hits enter, the application quits and execution terminate

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 18:31

    Don't forget that if you perform a System.exit(), you can't easily later use your methods in a standalone library. If you want to reuse your code outside your existing solution (and you may not now, but decide to do so in the future), then you'll then have to revisit and refactor appropriately.

    Otherwise the worst-case scenario is that you take the existing code without noticing the System.exit()s, use it and then have your library exit unexpectedly in a new application.

    Just something to bear in mind re. code-reuse.

提交回复
热议问题