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

斯卡拉 – 特征之间的区别?

发布时间:2020-12-16 08:44:34 所属栏目:安全 来源:网络整理
导读:这两个特质之间有什么区别吗? scala trait Bar[A : Foo] { | def bippy(x: A): A | }defined trait Bar 和 scala trait BarTwo { | type A : Foo | | def bippy(x: A): A | }defined trait BarTwo 编辑: 根据我的问题,他们名字的不同并不是一个有意义的区
这两个特质之间有什么区别吗?

scala> trait Bar[A <: Foo] {
     |    def bippy(x: A): A
     | }
defined trait Bar

scala> trait BarTwo {
     |   type A <: Foo
     |
     |   def bippy(x: A): A
     | }
defined trait BarTwo

编辑:

根据我的问题,他们名字的不同并不是一个有意义的区别.我正在寻找这两种特质构造之间的任何区别.

解决方法

在大多数实际情况中,没有区别,正如@AkosKrivachy评论的那样,它们被安排完全等同.然而,虽然 the official documentation表示

it is often possible to turn abstract type members into type parameters of classes and vice versa.

它最后还说明了这一点

Furthermore,there are cases where it is not possible to replace abstract types with type parameters.

可悲的是,我找不到那些案例的描述:-(

我发布这个作为答案以防万一更好的答案可能不会出现,你可能想关闭它,但我们希望.

(编辑:李大同)

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

    推荐文章
      热点阅读