same method, different types of parameters

S

san

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
 
A

Arnaud Berger

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top