Some questions about covariance in Scala
I'm trying to understand covariance in Scala, but I cant find any examples that help me with this problem. I' ve got this code: class GenericCellImm[+T] (val x: T) {} and it compile well, but when I use it class GenericCellMut[+T] (var x: T) { } it doesn't compile. Why I can't use var (but I can use val) when I'm writing this code? How can I fix it? Also here is similar situation abstract class Sequence[+A] { def append(x: Sequence[A]): Sequence[A]} What is the problem? You can't write def append(x: Sequence[A]): Sequence[A]} , as A is in contravariant position in the append argument, while