same method, different types of parameters

Discussion in 'Java' started by san, May 10, 2005.

  1. san

    san Guest

    Hi
    Is it possible in Java like in C++ with templates, to write a Method
    only once, for different types of parameter? Or do I have to write the
    same methode for each parameter type I have?
    Thanks for your help
    san, May 10, 2005
    #1
    1. Advertising

  2. Hi,

    What is possible is to specify a "larger" type :

    say for basic types, if your method expects a type "long", you may call it
    with type "int" or type "long" or type "short"

    For Objects, if your method expects type "Object", you may call it with any
    kind of object.

    Apart from that, maybe Java 1.5 gives other possibilities that I ignore.

    Regards,

    Arnaud



    "san" <> a écrit dans le message news:
    ...
    > Hi
    > Is it possible in Java like in C++ with templates, to write a Method
    > only once, for different types of parameter? Or do I have to write the
    > same methode for each parameter type I have?
    > Thanks for your help
    >
    Arnaud Berger, May 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    805
  2. Christopher Brewster
    Replies:
    5
    Views:
    339
    John Machin
    Nov 14, 2008
  3. George Sakkis
    Replies:
    8
    Views:
    287
  4. bluebaron
    Replies:
    3
    Views:
    736
    Jonathan N. Little
    Nov 4, 2009
  5. Guest
    Replies:
    2
    Views:
    177
    Foo Man Chew
    Dec 29, 2003
Loading...

Share This Page