There is no copy() method in the case class .
Check out all the methods generated in the case class :
$ echo 'case class T(a1: String, a2: Int)' > test.scala $ scalac -Xprint:typer test.scala
You will find this method:
<synthetic> def copy(a1: String = a1, a2: Int = a2): T = new T(a1, a2);
There Java no default parameters in Java , so you need to specify all parameters. Therefore, the copy method is useless in Java .
case class must be immutable, so you do not need copy without changing the fields.
Instead of obj2= obj.copy() you can use obj2= obj .
senia source share