Could you technically call the string[] anything in the main method?

前端 未结 3 655
独厮守ぢ
独厮守ぢ 2020-12-12 07:18

The header for the main method is

public static void main (String[] args)

Could you technically replace \"args\" with anything

相关标签:
3条回答
  • 2020-12-12 07:40

    args is just a name for the argument in a method. You can rename it to whatever you want. The JVM doesn't need to know what the argument is named; only the type, String[], is important.

    dont break the start point of the app

     static void main(String[] whateverYouNeed)
    
    0 讨论(0)
  • 2020-12-12 07:46

    You can rename it to any proper Java identifier. The application needs to be able to accept multiple command-line arguments. It doesn't necessarily have to be an array, you can use varargs also.

     static void main(String... whateverYouNeed)
    
    0 讨论(0)
  • 2020-12-12 07:46

    The main method could be written as:

    • public static void main (String[] args)
    • public static void main (String args[])
    • public static void main (String... args)

    The parameter name args could be replaced with any valid Java identifier like blah, programArgs, and so on. It's an array to accept any number of command line arguments. For example:

    • java programName has no command line arguments
    • java programName arg1 arg2 has 2 command line arguments
    0 讨论(0)
提交回复
热议问题