且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

调用Java主要方法

更新时间:2023-11-18 15:14:52

从另一种方法调用main方法通常被认为是不好的编程习惯.这可能会导致出现一系列问题,例如无限循环,无限递归等.您的主要方法应包括程序需要操作的高级功能,通常希望它尽可能简单.作为一种很好的检查"方式,请问自己是否可以将此功能制成自己的单独方法?如果是这样,那为什么不这样做呢?然后,如果您需要再次拨打该电话,则可以使用单独的方法进行操作.

It is generally considered bad programming practice to call the main method from another method. This can lead to a whole list of problems such as infinite loops, infinite recursion, etc. Your main method should include high level functionality that your program needs to operate, you generally want it to be as simple as you can keep it. As a good kind of "check" ask yourself can I make this functionality into its own separate method? If so then why not do that? Then if you ever need to make that call again, you have a separate method to do so.