Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ellipsis in main method?

Tags:

java

If i use ellipsis in main method would it make any difference?

public static void main(String... args) {

}
like image 476
Harinder Avatar asked Dec 06 '22 17:12

Harinder


2 Answers

No difference. That "ellipsis" syntax is called varargs, whose parameter type is actually an array.

This means there are actually three possible signatures of a valid main() method:

public static void main(String[] args) {}
public static void main(String... args) {}
public static void main(String args[]) {}
like image 112
Bohemian Avatar answered Dec 09 '22 07:12

Bohemian


It does not make any difference, since the JVM turns the ellipsis (also called "varargs") into an array at "compile" time:

void myMethod(final X... args)

is exactly the same as

void myMethod(final X[] args)

or (less frequent)

void myMethod(final X args[])
like image 42
fge Avatar answered Dec 09 '22 06:12

fge