Container Contravariance was Re: [typing] Type-erasure re generics

Jesse Phillips jessekphillips+D at gmail.com
Wed Sep 29 11:20:11 PDT 2010


Jesse Phillips Wrote:

> I will first quote Wikipedia about C#[1]:
> 
> "For example, in C# 3.0 generic parameters did not support co or contravariance; List<A> was not equivalent to List<TypeDerivedFromTypeA> as one might intuit; however, this is now supported in C# 4.0, though standard arrays have always supported covariance & contravariance since .NET was introduced."
> 
> Then I will show an example that does compile[2]:
> 
> void main() {
>     A[] = [new B(), new A()];
> }
> 
> 1. http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
> 2. http://ideone.com/ZzDTs


Actually my example code should have been this[1]:

class A {}
class B:A {}
 
void main() {
    A[] a = new B[6];
}


1. http://ideone.com/Q59iD


More information about the Digitalmars-d mailing list