aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes [n] Strange Variable Argument behaviour? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "[n] Strange Variable Argument behaviour?" Watch "[n] Strange Variable Argument behaviour?" New topic
Author

[n] Strange Variable Argument behaviour?

Nirav Patel
Greenhorn

Joined: May 27, 2005
Posts: 22
Predict the output of following code.
pass 1 2 as command line arguments.



Shouldn't it be "Two arg printUS" followed by the two values?
It's not.
Answer is "in printUS" followed by the two values.
If i call explicitely than it calls specific method for two arg paramers but not when it's from command line.
After all here command line is also an array of

Any idea?

{JDK 5.0, Windows XP Pro}

TIA.
Nirav


----<br />Nirav Patel<br />Software is the bottleneck in the digital world!
Nirav Patel
Greenhorn

Joined: May 27, 2005
Posts: 22
Hi group!
Is there any problem with my question or am I in the wrong forum?
Tapas Kumar
Greenhorn

Joined: Jul 29, 2005
Posts: 6
Hi Nirav,
Acccording to my understanding vararg String ...b is equivalent to
String[] b. Before java 1.5 a developer has to explicitly move string values to an array and call the method. Java 1.5 does this for us behind the scene.
Your method call is therefore with an array reference not with two String type parameter.Result should be as you got.
Hope this helps
Tapas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [n] Strange Variable Argument behaviour?