Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

method dynamic parameter lists?

Thread view: 
timasmith@hotmail.com - 17 Apr 2006 16:08 GMT
I have the following framework code

    public static Vector getParameter(int i) {
        Vector v = new Vector(1);
        v.add(new Integer(i));
        v.add(new Integer(k));
        return v;
    }

... repeats with additional similar methods up to any beyond

    public static Vector getParameter(int i, int j, int k, int l) {
        Vector v = new Vector(4);
        v.add(new Integer(i));
        v.add(new Integer(j));
        v.add(new Integer(k));
        v.add(new Integer(l));
        return v;
    }

How can I replace this.  For the developer it is very convenient
(single line of code) to use the above

....callMyMethod(getParameter(myId,anotherReferenceId,somePrimaryKey));

can I have something like this...

    public static Vector getParameter(int i...) {
                               Vector v = new Vector();
        Enumerate i {
           v.add(...);
                              }
        return v;
    }

thanks

Tim
Venkatesh - 18 Apr 2006 05:46 GMT
Guess u can have functions in java, taking variable number of
arguments. The following piece of code should work for your example:

public static Vector<Integer> getParameter(int ... params) {

       Vector<Integer> v = new Vector<Integer>();

       for (int cnt = 0; cnt < params.length; cnt++) {
           v.add(new Integer(params[cnt]));
       }
       return v;

}

To get more details, try googling on "java variable arguments"

-Venkatesh
timasmith@hotmail.com - 18 Apr 2006 20:08 GMT
I was beginning to wonder how far behind my knowlege of the language
had fallen.

However the above code:

The type Vector is not generic; it cannot be parameterized with
arguments <Integer>

and

Syntax error, varargs are only available if source level is 5.0

oh well, thanks for the thought.

thanks

Tim
Roedy Green - 18 Apr 2006 21:44 GMT
>Syntax error, varargs are only available if source level is 5.0

consider than 5.0 game out in 2004.  

We need to make Java self updating so that you need a techie to STOP
the auto-update.  What's the point of new features if you don't dare
use them?

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Andrew McDonagh - 18 Apr 2006 23:27 GMT
>> Syntax error, varargs are only available if source level is 5.0
>  
[quoted text clipped - 3 lines]
> the auto-update.  What's the point of new features if you don't dare
> use them?

hehe - try using that approach in the corporate world, where in a single
company (like mine) you have 000,000s PCs with Java on. Java updating
itself with new features is the last thing we want - it'll break more
than one app amongst those machines - it always does.

Hell, most corporates are only now just finishing their windows XP roll
out and XP is 4 years old with Windows Vista just around the corner.
Roedy Green - 19 Apr 2006 00:02 GMT
>hehe - try using that approach in the corporate world, where in a single
>company (like mine) you have 000,000s PCs with Java on. Java updating
>itself with new features is the last thing we want - it'll break more
>than one app amongst those machines - it always does.

That's fine. In the corporate world they can easily do the thing that
freezes the JVM and gives corporate control.  The default however
should be to autoupdate.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.