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 / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

A question about a generic method

Thread view: 
Richard - 30 Mar 2006 18:09 GMT
Hello,

The fill method in java.util.Collections has this signature:
<T> void fill(List<? super T> list, T obj)

I can't understand why the signature is not this one:
<T> void fill(List<T> list, T obj)
because with this last one you can call the method with these arguments
(Employee extends Person):
    List<Person> l = new ArrayList<Person>();
    l.add(new Person("john"));
    l.add(new Person("bob"));
    Employee e = new Employee("fred", 1000);
    Coll.fill(l, e);

(T is inferred into Person).

I can't find circumstances where the first signature is better than the
last one. Could you show me one?

Thanks in advance for your answer.

Richard
Dave Mandelin - 30 Mar 2006 20:00 GMT
I don't know either. I do know the type inference has more freedom with
the actual definition, because it can infer T to either Person or
Employee in your example, but I couldn't find a case where it actually
made a difference. Anyone know?

--
Need to get from a Foo object to a Bar object in Java?
   Ask Prospector:                http://snobol.cs.berkeley.edu
Want to play tabletop RPGs over the internet?
   Check out Koboldsoft RPZen:    http://www.koboldsoft.com


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.