5
votes

I try

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

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

but I get

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

Since Bar is a case class, it automatically defines a copy method with exactly this signature.

Why doesn't the Foo class satisfy the interface defined by the trait Bar?

1
The case class won't implement copy if it's inherited, even if abstract. There is a duplicate of this somewhere.Michael Zajac
@m-z, found it! stackoverflow.com/questions/17937020/… That is itself marked as a duplicate, IMO incorrectly.Paul Draper

1 Answers

5
votes

I am quoting the 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.