Using int Instead Of String: public static void main (int[] args)

前端 未结 4 581
一生所求
一生所求 2020-12-16 07:19

I was under the impression that the main method had to have the form \"public static void main (String[] args){}\", that you couldn\'t pass int[] arguments.

However,

4条回答
  •  醉梦人生
    2020-12-16 08:08

    Well, you can have any method with the name main with any number of arguments. But the JVM will look for the main method with the exact signature public static void main(String[]).

    The main method you have defined is just another method to the class.

    I don't have access to Windows now, but let me try it in a while. I did try on Fedora and of course I got the following exception:

    Exception in thread "main" java.lang.NoSuchMethodError: main
    

    Note that the class would compile fine because of the above said reason.

    Update: I tested on Windows 7 and the results are same. I'm surprised how you said it worked for you.

提交回复
热议问题