A question about a generic method
- From: Richard <grin@xxxxxxxx>
- Date: Thu, 30 Mar 2006 19:09:22 +0200
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
.
- Follow-Ups:
- Re: A question about a generic method
- From: Dave Mandelin
- Re: A question about a generic method
- Prev by Date: Re: Add an actionListener ActionEvent in jsp
- Next by Date: Upload Images in JSP
- Previous by thread: Input/Output program Compiles but doesn't run
- Next by thread: Re: A question about a generic method
- Index(es):