File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 255

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 ?