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

scala – 在扩展自我类型的特征时非法继承

发布时间:2020-12-16 18:25:53 所属栏目:安全 来源:网络整理
导读:我对以下代码感到困惑: trait T1 { type S } trait T2 { self: T1 = case class ClS(s: S) } object O extends T2 { } 它给出以下错误消息: illegal inheritance; tests.O.type does not conform to tests.T2’s selftype tests.T2 with tests.T1 出了什么
我对以下代码感到困惑:

trait T1 {
        type S
    }

    trait T2 {
      self: T1 =>

       case  class ClS(s: S)
    }

    object O extends T2 {

    }

它给出以下错误消息:

illegal inheritance; tests.O.type does not conform to tests.T2’s
selftype tests.T2 with tests.T1

出了什么问题?我用T2扩展O的原因是我想在O中引用类CLS,我该如何实现呢?

解决方法

特质T2有一个合同,上面写着:如果你继承我,你也应该继承T1.

object O extends T2 with T1

然后,您可能会收到类型S未定义的错误.这是一件好事,因为它用于CLS的定义

(编辑:李大同)

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

    推荐文章
      热点阅读