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