- It is important to notice that Test is not a type but Test[Any] or Test[String] is.
- At a place where Test[Any] is expected, you can not give Test[String] ... as was my notion due to mostly being a java programmer.
Contravariance is exactly opposite of covariance and is supported with '-' symbol instead of '+'
Similarly, to constraint type parameters we can say things like...
class MyClass[V <: AnotherType]
This puts the constraint that V has to be a subtype of
AnotherType
andclass MyClass[V >: AnotherType]
puts the constraint that V has to be a type that is extended by
AnotherType
No comments:
Post a Comment