Eclipse 约定中的主要方法
我注意到,如果我将多个文件放入一个包中,放入 Eclipse 中的单个项目中,而每个文件都有自己的 main 方法 - 运行时环境不会抛出错误。
据我所知,每个项目应该只有一个主要方法。 或者一个项目有几个主要方法可以吗?在这种情况下,放置主要方法的最佳方法是什么?
I've noticed that if I put number of files into one package into a single project in Eclipse, while each file has it's own main method- the run time environment won't throw an error.
As I know each project should have only one main method.
or is it OK to have few main methods for a project- in this case what is the best way to place the main methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以拥有任意多个主要方法,编译器或运行时不会关心。就最佳实践而言,为了清晰起见,我会倾向于使用单一主要方法。在开发过程中,我可能会向类中添加一个 main 函数以进行独立测试,但在交付更改之前删除该方法。
You can have as many main methods as you like, the compiler or runtime won't care. As far as a best practice goes I would lean towards a single main method for clarity. During development I might add a main to a class for standalone testing purposes but then remove the method before delivering the change.