do D support something like C# 4.0 co/contra-variance?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Oct 20 04:29:24 PDT 2010


On 15/10/2010 13:49, Sean Reque wrote:
> Java doesn't have variant generic type parameters. Wildcard types in Java are NOT the same thing and are certainly not more powerful. C# doesn't have wildcard types because it doesn't implement generics with erasure. See http://stackoverflow.com/questions/527766/what-is-the-equivalent-of-java-wildcards-in-c-generics.

What do you mean they are not the same? Yes, they don't work the same 
way, their semantics is fairly different, but they are both attempting 
to address the same problem: To improve safety/expressiveness in the 
type system, with regards to variance in generic type parameters.

Why is C#'s approach to variance is more powerful than Java's, and not 
the other way around? ( You're not off to a good start when the article 
you mentioned exposes a scenario that Java can express, but C# can't, at 
least not clearly. ;) )

And think carefully before you justify the above by saying that C#'s 
generic are not erasures (ie, the generic parameters information is 
preserver at runtime).

-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list