I’ve read that Scala’a case class construct automatically generates a fitting equals and hashCode implementation. What does exactly the generated code look like?
I’ve read that Scala’a case class construct automatically generates a fitting equals and hashCode
Share
As my professor used to say, only the code tells the truth! So just take a look at the code that is generated for:
We can instruct the Scala compiler to show us the generated code after the different phases, here after the typechecker:
So you can see that the calculation of the hash code is delegated to ScalaRunTime._hashCode and the equality depends on the equality of the case class’ members.