I have made heavy use of case classes in my code, replying on the underlying equality definitions of case class to behave correctly. Then now I found that I need to add another field member to a case class.
- So if I add a
varfield member in case class, will it mess up the equality attributes for the case class? - If 1 is yes, then what if I just change the
varfield value once, after that, no any reassignment will happen, before the case class goes into any collections or do equality comparison, will that still mess up the equality behaviors?
Case class equality is based solely on its primary constructor attributes, whether they’re
varorval(yes, you can make themvarby giving an explicitvarto override the impliedvalthat case class constructor args possess.) Adding properties in the body of acase classdoes not influence the compiler-generatedequals(other: Any)method.Witness:
In the REPL:
And all jamie’s points about concurrency are valid, too.