Alex Rivera | Logout

How does the Java array argument declaration syntax "..." work?

Asked 2010-11-18T02:23:24.063
58

I have been writing java for a while, and today I encountered the following declaration:

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

}

Note the "dot dot dot" in the array declaration, rather than the usual bracket []. Clearly it works. In fact I wrote a small test and verified it works. So, I pulled the java grammar to see where this syntax of argument declaration is, but did not find anything.

So to the experts out there, how does this work? Is it part of the grammar? Also, while I can declare function like this, I can't declare an array within a function's body like this.

Anyway, do you know of any place that has this documented. It is curiosity, and perhaps not worth of any time invested in it, but I was stumped.

Edit
Report

1 Answer

3

It means you can pass zero or more Member objects to the setMembers() method. In the setMembers method, members will have array semantics.

answered 2011-01-06T19:29:50.033

Your Answer