加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 对于“Box [T]”,我可以说“Box type是covariant”,它

发布时间:2020-12-16 09:54:49 所属栏目:安全 来源:网络整理
导读:假设我定义了一个类型构造函数Box: trait Box[+T] 什么是正确的? 类型Box是协变的 类型构造函数Box是协变的 类型参数T是协变的 类型构造函数中的类型参数T是协变的 如果所有这些都不正确,那么正确的表达方式是什么? 解决方法 关于 Functional Programming
假设我定义了一个类型构造函数Box:

trait Box[+T]

什么是正确的?

>类型Box是协变的
>类型构造函数Box是协变的
>类型参数T是协变的
>类型构造函数中的类型参数T是协变的
>如果所有这些都不正确,那么正确的表达方式是什么?

解决方法

关于 Functional Programming in Scala书中的差异:

In the declaration trait List[+A],the + in front of the
type parameter A is a variance annotation which signals that A
is a covariant
or “positive” parameter of List. This means
that,for instance,List[Dog] is considered a subtype of
List[Animal],assuming Dog is a subtype of Animal.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读