By default, no specific equals and hashCode are generated (thus, they check object identity).
For data classes, hashCode and equals are based on property values. I’ll write algorithm steps in words instead of pseudocode:
hashCode:
- Calculate hashCode for each property declared as constructor parameter in current class
- Return h1 × 31n−1 + h2 × 31n−2 + … + hn
equals (let parameter be named that):
- Check if that is instance of our class (instanceof-check)
- For each property declared as constructor parameter in current class, check if this.prop1 equals to that.prop1 (by invoking equals method).
As I have already said in other thread, data class inheritance is not supported. If we support it, we’ll consider stricter algorithm for equals().