Unable to copy case class with duplicate parameters

Why can't I use the copy method of the case class with duplicate parameters?

For example, why is the last line of this code giving me an 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

+4
source share
1 answer

According to scala specifications, the method is copynot generated by the compiler for case classes that have a repeating parameter.

A method named copy is implicitly added to each case class if the class already does not have a member (directly defined or inherited) with this name or the class has a repeating parameter.

+9
source

Source: https://habr.com/ru/post/1673493/


All Articles