admin管理员组文章数量:1357307
Consider this example from book Programming in Scala, 5th Edition by Martin Odersky (Chapter 18 · Type Parameterization)
Here - the following class Cat
is described:
abstract class Cat[-T, +U]:
def meow[W−](volume: T−, listener: Cat[U+, T−]−)
: Cat[Cat[U+, T−]−, U+]+
- the concepts of covariance and contravariance for the class level type parameters
T
andU
perfectly make sense.
But the fact that the method level type variable W
is being classified as -ve ie as Contravariant - is not very clear. Since we are neither using it in the method argument determination - nor are we using it in the return type.
Why is the example quoting it as contravariant and not invariant?
本文标签: genericsVariance Annotation for an independent Method level type parameters in scalaStack Overflow
版权声明:本文标题:generics - Variance Annotation for an independent Method level type parameters in scala? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744075357a2586643.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论