• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

[n] Strange Variable Argument behaviour?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi group!
Is there any problem with my question or am I in the wrong forum?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic