Re: Object or <T> parameters

Daniel Bonniot <[email protected]> Sun, 22 Feb 2004 17:48:25 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
> What is the difference now between these?
>
> Object doSomething(){}

This returns an object, about which you have no typing information at all 
(everything being an Object). The only things you will be able to with the 
result are calling methods available on all values (getClass, toString) and 
"testing" the actual class the value belongs to, either by using instanceof, 
or by calling a method that accepts any vaue, but that is specialized on 
certain classes.
>
> <T> T doSomething(){}

This one returns a value, which has any type you might want it to have. This 
means you can use the returned value in any way you want. Of course, the only 
way to safely implement such a method is to make sure it never returns 
(throws an exception for instance).

On the other hand, 
  void doSomething(Object)
and 
  <T> void doSomething(T)
are equivalent, they both mean that the argument might be anything.

Daniel



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click