7
votes
Vote UpVote

Generics and variance

Delphi sorcery – When working with generic collections there is often the question: "Why can't I just assign my TList<TPerson> to a variable of TList<TEntity>? TCustomer inherits from TEntity!" There is something called covariance and contravariance - but the bad news are: Delphi does not support variance. But we are trying to understand what this is all about anyway, shall we? Let's take a look at our TList<TPerson> again and find out why it is invariant as the Wikipedia article says. Invariant means it's not compatible with either TList<TEntity> nor TList<TCustomer> (TCustomer ...
Favorite? Off-Topic? noreply@blogger.com @ 2014-10-09 23:46

Statistics

Visits: 1470
Votes: 7
Favorites: 1
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

DCadarn
Hector_McG
Jeroen Pluimers
Jørn E. Angeltveit
Linas
Mohammed Nasman
Radosław Kokoć
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

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