Why does Java main() method accept an array of String args?

前端 未结 8 1428
情深已故
情深已故 2021-01-14 06:20

Since its possibly one of the most widely used methods of the Java language, why does it have to accept an array of Strings and doesn\'t work without it? For example, I coul

8条回答
  •  不要未来只要你来
    2021-01-14 07:10

    I agree that it could be more flexible. In C# for instance, all of these are acceptable entry points:

    static void Main()
    static void Main(string[] args)
    static int Main()
    static int Main(string[] args)
    

    The versions returning int use the return value as the exit code for the process. If you don't care about receiving any arguments, you can use one of the versions which doesn't take any. Any arguments given when the program is launched are ignored.

    So yes, it could be more flexible - but it's never struck me as a significant problem in Java.

提交回复
热议问题