| Author |
dynamic parameters to java methods
|
Enge Chall
Ranch Hand
Joined: Nov 22, 2005
Posts: 30
|
|
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
|
Not everything that counts can be counted, and not everything that can be counted counts.
|
 |
Mani Ram
Ranch Hand
Joined: Mar 11, 2002
Posts: 1140
|
|
|
Only with JDK 5. Varargs
|
Mani
Quaerendo Invenietis
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
Moving to Java In General (Beginner)
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Naveen K Garg
Ranch Hand
Joined: Nov 28, 2005
Posts: 105
|
|
|
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
Joined: Nov 22, 2005
Posts: 30
|
|
|
Thanks guys. varargs was a useful advise.
|
 |
 |
|
|
subject: dynamic parameters to java methods
|
|
|