Eclipse 约定中的主要方法

发布于 2025-01-06 11:40:38 字数 148 浏览 3 评论 0原文

我注意到,如果我将多个文件放入一个包中,放入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨夜星沙 2025-01-13 11:40:38

您可以拥有任意多个主要方法,编译器或运行时不会关心。就最佳实践而言,为了清晰起见,我会倾向于使用单一主要方法。在开发过程中,我可能会向类中添加一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文