Ernest Friedman-Hill wrote:Hi Pat,
Well, to first order, you create TalentedPerson as a subclass of Person, and then any function that took a Person or List<Person> as an argument will also accept TalentedPerson or List<TalentedPerson>. There you go, all done.
Garrett Rowe wrote:To be clear, a method that takes a List<Person> argument will not accept a List<TalentedPerson>. Generic type parameters aren't covariant, a List<TalentedPerson> is not a subclass of List<Person>. For the method to accept both types of Lists, it must be declared to take a List<? extends Person>.
Campbell Ritchie wrote:Yes, that is correct. There are details in the Java™ Tutorials, where there is a section about subtyping.
Garrett Rowe wrote:I only wanted to clarify that in Java a method that expects a List<Person> will not accept a List<TalentedPerson>. This may not be what your original post was about, but it was implied by Ernest's reply.
Garrett Rowe wrote:That's exactly not what i was talking about. I was talking about a List<TalentedPerson>, not a List<Person> that happened to be filled with TalentedPerson instances. A List<TalentedPerson> is not a subtype of a List<Person>