I want to use copy on a case classes. But scala insists I specify all the properties that were declared in the second paranthsis.
Example:
package academic.classes.casec.copy
object TstClz {
val f = DataMe("SD") ( "B")
val x = f.copy("x 4")()//Error : not enough arguments for method copy: (b: String, c: String)academic.classes.casec.copy.DataMe. Unspecified value parameters b, c.
}
case class DataMe (a : String, a1 : String = "a1")(b:String, c: String = ""){}
Is this a feature or a bug? What can I do to make it work the way I want (get the values of b and c from the instance whose copy is being made?
I don't think that's possible. In this bug report, you can find the following statement:
Martin says: case class ness is only bestowed on the first argument list
the rest should not be copied.
Later, there was a "bug fix" which made copy to return at least a function representing the second parameter list, but that behavior was reverted in this commit.
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