Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamic parameters to java methods

 
Enge Chall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to implement the method which accepts dynamic parameters at run time.
eg: I want to invoke f1(), f1(1), f1(1, "hello"), f1(1, "hello", 200)... This is decided only at runtime.

So the qn is: is there a way to implement f1() ???

appreciate ur answers.
Thanks
Chall
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only with JDK 5. Varargs
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner)
 
Naveen K Garg
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use a hashMap object as a parameter to the method and put any number of parameters in forms of key/value pair.
 
Enge Chall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. varargs was a useful advise.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic