Vote UpVote

Generics and the Covariance Problem

TURBU Tech – Since some version of this question keeps showing up on StackOverflow, and the answer’s always basically the same, I figured I may as well write up a post on here that people can link to.  Here’s the question, in simplified form: “Why can’t I pass a TList<TMyDerivedObject> to a function that’s expecting a TList<TMyBaseObject>?  You can pass a TMyDerivedObject to a parameter expecting TMyBaseObject, so why doesn’t it work for lists?” It really looks like it ought to be that simple, but unfortunately it’s not.  Trying to do this gets ...
Favorite? Off-Topic? Mason Wheeler @ 2010-06-22 22:52


Visits: 828
Votes: 7
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Charles Ardour
Daniele Teti
Mohammed Nasman
Primoz Gabrijelcic
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)