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

scala – 案例类扩展特征不能使用副本

发布时间:2020-12-16 18:16:54 所属栏目:安全 来源:网络整理
导读:我试试 trait Foo[A] { def copy(int: Int): A}case class Bar(int: Int) extends Foo[Bar] 但我明白了 error: class Bar needs to be abstract,since method copy in trait Foo of type (int: Int)this.Bar is not defined 由于Bar是一个案例类,它会自动定
我试试

trait Foo[A] {
  def copy(int: Int): A
}

case class Bar(int: Int) extends Foo[Bar]

但我明白了

error: class Bar needs to be abstract,since method copy in trait Foo of type (int: Int)this.Bar is not defined

由于Bar是一个案例类,它会自动定义具有此签名的复制方法.

为什么Foo类不满足trait Bar定义的接口?

解决方法

我引用了 Scala’s specification:

A method named copy is implicitly added to every case class unless the class already has a member (directly defined or inherited) with that name,or the class has a repeated parameter.

(编辑:李大同)

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

    推荐文章
      热点阅读