Why can I not use the copy method of a case class with repeated parameters?
For example why does the last line of this code give me the error?
case class A(i: Int)
case class B(i: Int*)
val a = A(1).copy(i = 2)
val b1 = B(i = Seq(4, 5): _*)
val b2 = B(2, 3).copy(i = Seq(4, 5): _*)
value copy is not a member of B
According to scala specs the copy
method is not generated, by the compiler, for case classes having a repeated parameter.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With