2

这只是一个命名约定?为什么在从 shell 执行程序时不能调用任何方法,例如

$> java myPackage.MyClass.myOwnEntryPoint(String[] str)
4

2 回答 2

6

是的,这是一个命名约定,继承自 C。这样做的好处是,通过查看代码很容易找出哪个方法应该是 main 方法。

于 2011-03-07T11:47:44.640 回答
1

The main method is the entry point that the java program for running Java applications (as opposed to applets or other things) looks for. As far as I'm aware, there's no way to tell java to look for a different method instead, so it's not just a naming convention; if you want your application to run (via the standard java tool, anyway), you want to give it a main method with the appropriate signature. (You can play games with static initializers, but that's another thing entirely.)

The name main is inherited from C, but it's not just a convention.

于 2011-03-07T11:54:39.590 回答