Why is Function[-A1,…,+B] not about allowing any supertypes as parameters?

前端 未结 5 1544
别那么骄傲
别那么骄傲 2020-12-01 00:00

I believe one can define covariance (at least, for objects) as \'the ability to use a value of a narrower (sub) type in place of a value of some wider (super) type\', and th

5条回答
  •  一向
    一向 (楼主)
    2020-12-01 00:08

    Covariant means converting from wider (super) to narrower (sub). For example, we have two class: one is animal (super) and the other one is cat then using covariant, we can convert animal to cat.

    Contra-variant is just the opposite of covariant, which means cat to animal.

    Invariant means it's unable to convert.

提交回复
热议问题