为什么Java程序需要“main()”?方法?
问题描述:
这只是一个命名惯例?为什么在从shell执行程序时不能调用任何方法,例如
It is just a naming convention? Why can't any method be called while executing a program from a shell e.g
$> java myPackage.MyClass.myOwnEntryPoint(String[] str)
答
是的,这是一个继承自C的命名约定。优点是这个通过查看代码,找出哪个方法应该是主要方法非常简单。
Yes, that's a naming convention, inherited from C. The advantage is that this way, it's very simple to find out which method is supposed to be the main method just by looking at the code.