Recently I\'ve noticed that variance annotations can be used in type aliases. Here is example from Predef:
type Function[-A, +B] = Function1[A,
If the abstract type is only declared (as in Domain), the invariance will be enforced. If the abstract type is defined to have a more relaxed variance, this is respected once known (as in DomainImpl):
trait Domain {
type InvList[T]
val xi: InvList[Int]
private val xa: InvList[Any] = xi // won't compile
}
class DomainImpl extends Domain {
type InvList[T] = List[T]
val xi: InvList[Int] = List(1)
private val xa: InvList[Any] = xi // will compile
}