• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[n] Strange Variable Argument behaviour?

 
Nirav Patel
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nirav Patel
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi group!
Is there any problem with my question or am I in the wrong forum?
 
Tapas Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic