Why doesn’t the example compile, aka how does (co-, contra-, and in-) variance work?

Generically, a covariant type parameter is one which is allowed to vary down as the class is subtyped (alternatively, vary with subtyping, hence the “co-” prefix). More concretely: trait List[+A] List[Int] is a subtype of List[AnyVal] because Int is a subtype of AnyVal. This means that you may provide an instance of List[Int] when a … Read more