#scala #variances
Similarly, -T
would declare T
to be used only in contravariant positions.
If you want to change selection, open document below and click on "Move attachment"
Variances - Scala Documentationquot;"
}
object VariancesTest extends App {
var s: Stack[Any] = new Stack().push("hello");
s = s.push(new Object())
s = s.push(7)
println(s)
}
The annotation +T declares type T to be used only in covariant positions. <span>Similarly, -T would declare T to be used only in contravariant positions. For covariant type parameters we get a covariant subtype relationship regarding this type parameter. For our example this means Stack[T] is a subtype of Stack[S] if T is a subtype of S.