Top "Covariance" questions

Covariance, contravariance and invariance describe how the existing type inheritance hierarchy changes when subjected to some transformation (such as usage within generics).

Does C# support return type covariance?

I'm working with the .NET framework and I really want to be able to make a custom type of page …

c# covariance
How can i cast into a ObservableCollection<object>

How can i cast from ObservableCollection<TabItem> into ObservableCollection<object> this doesnt work for me (ObservableCollection&…

c# observablecollection covariance
Contravariance explained

First of, I have read many explanations on SO and blogs about covariance and contravariance and a big thanks goes …

c# c#-4.0 covariance contravariance
C# variance problem: Assigning List<Derived> as List<Base>

Look at the following example (partially taken from MSDN Blog): class Animal { } class Giraffe : Animal { } static void Main(string[] args) { // …

c# covariance
How do I convert from List<?> to List<T> in Java using generics?

In Java, how do I convert List<?> to List<T> using a general purpose method so …

java generics list covariance
How can I use covariant return types with smart pointers?

I have code like this: class RetInterface {...} class Ret1: public RetInterface {...} class AInterface { public: virtual boost::shared_ptr<RetInterface&…

c++ covariance smart-pointers
Casting from IEnumerable<Object> to IEnumerable<string>

Recently I found a very surprising behavior in c#. I had a method which takes IEnumerable<Object> as …

c# covariance contravariance
scala - Any vs underscore in generics

What is the different between the following Generics definitions in Scala: class Foo[T <: List[_]] and class Bar[T &…

scala generics covariance any existential-type
C# casting an inherited Generic interface

I'm having some trouble getting my head around casting an interface I've come up with. It's an MVP design for …

c# generics interface casting covariance
Generic wildcards in variable declarations in Scala

In Java I might do this: class MyClass { private List<? extends MyInterface> list; public void setList(List<…

java generics scala covariance contravariance