Understanding Covariance and Contravariance in C# 4.0

You may want to look at this blog, he does a fantastic job of explaining it, but I think it will take more examples to clear it up for people, as this gets into a very hard-to-understand area, but, the quote below from the article sums it up well. http://hestia.typepad.com/flatlander/2008/12/c-covariance-and-contravariance-by-example.html “covariance and contravariance” means that … Read more

What is the difference between covariance and contra-variance in programming languages? [closed]

Covariance is pretty simple and best thought of from the perspective of some collection class List. We can parameterize the List class with some type parameter T. That is, our list contains elements of type T for some T. List would be covariant if S is a subtype of T iff List[S] is a subtype … Read more

Why are contravariant parameter types in Java not allowed for overriding?

Because that’s called overloading. In particular, the return type type can be covariant because it is not considered when overloading, and it therefore still matches the superclass or interface’s implementation. Parameters are considered when overloading. You very well might have an optimization with Number doSomethingWithNumber(Integer value) compared to Number doSomethingWithNumber(Number value).

Contravariance explained

Update: Ooops. As it turned out, I mixed up variance and “assignment compatibility” in my initial answer. Edited the answer accordingly. Also I wrote a blog post that I hope should answer such questions better: Covariance and Contravariance FAQ Answer: I guess the answer to your first question is that you don’t have contravariance in … Read more