Can we use those 3 dots to create an array at the place of square brackets, like we used it above?? If not then why we are using this declaration only for main??
public static void main(String[] args)
or
public static void main(String... args)
From the above program, we can say that Java can have multiple main methods but with the concept of overloading. There should be only one main method with parameter as string[ ] arg.
Two of these components comprise the method signature: the method's name and the parameter list.
These are not two different signatures - under the hood, it is the same signature; the difference is that the compiler uses three dots to allow invocations with variable argument lists.
Since you never invoke main
directly (well, you shouldn't be, anyway) the difference shouldn't matter to you. The first form of the signature is the first thing you see in the elementary books on Java, so one should stick to square brackets to gain "instant familiarity" by the readers of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With