There is no method copy()
in case class
.
Let's see all methods generated in case class
:
$ echo 'case class T(a1: String, a2: Int)' > test.scala
$ scalac -Xprint:typer test.scala
You'll find this method:
<synthetic> def copy(a1: String = a1, a2: Int = a2): T = new T(a1, a2);
There are no default parameters in Java
, so you have to specify all parameters. So method copy
is useless in Java
.
case class
should be immutable, so you don't need to copy
it without changing fields.
Instead of obj2= obj.copy()
you can use obj2= obj
.