Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot copy case class with repeated parameters

Tags:

scala

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

like image 450
user79074 Avatar asked Jan 05 '23 06:01

user79074


1 Answers

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.

like image 131
Federico Pellegatta Avatar answered Jan 06 '23 19:01

Federico Pellegatta