Why is String[] args required in Java?

前端 未结 6 758
终归单人心
终归单人心 2020-12-03 21:33

I understand that String[] args is an array of strings passed into main as parameters.

java Print \"Hello, World!\"

 

         


        
6条回答
  •  旧时难觅i
    2020-12-03 21:57

    The Java runtime system looks specifically for a method with a single String[] type parameter, because it wants to pass the parameters to your main method. If such a method is not present, it informs you through an exception.

    If you want to treat the (string) command line parameters as integers or booleans, you are expected to do the conversion yourself. This allows you to handle the condition where somebody enters "ponies" where you expect an integer.

提交回复
热议问题