Scala 泛型中的协变(covariant)与逆变(contravariant)符号
看到这个问题《+- Signs in Generic Declaration in Scala》下面有一个很有意思的答案:
“+” and “-“ mean covariant and contravariant types respectively. In short, it means that:
PartialFunction[-A1, +B1] <: PartialFunction[-A2, +B2] only if A1 :> A2 and B1 <: B2, where <: is subtyping relationship.
简而言之,-
意味着逆变成立,+
意味着协变成立。
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.