This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why does this method call compile with only one argument ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Why does this method call compile with only one argument ?" Watch "Why does this method call compile with only one argument ?" New topic
Author

Why does this method call compile with only one argument ?

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Because String... is a var-arg which is a convenience for passing an array.

So if you do



The compiler will turn it into



which is a valid String array.

If you omit this argument completely as in your example, the compiler does this:



Which is a 0 sized String array and perfectly legal.


JDBCSupport - An easy to use, light-weight JDBC framework -
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 219
Hey Harry,

... operator represents 0 or more arguments . In this case the function can be called in various formats.. I believe, the below code would clear your doubt.




The output would be

The array elements are -
21 22
The array elements are -
20 30 40
The array elements are -
1 2 3 4
The array elements are -


Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does this method call compile with only one argument ?
 
Similar Threads
Parameter passing into a method-Examlab
Overloaded method call
Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -
How pattern works?
Pattern and matcher