Yes, implementing hashCode() is trivial thanks to Objects.hash(), but this method allows passing a list of properties. If you want to ensure equals() and hashCode() are based on the same set of properties (which makes holding up their contract easier), you can just pass the same stored list of properties to kotlinEquals() and kotlinHashCode() and not worry about missing a property.
It's also somewhat verbose, especially for larger objects, to write a property name twice, once to retrieve the property for equals() if using kotlinEquals() and once to retrieve the value for hashCode() if using Objects.hash().
Yes, implementing
hashCode()
is trivial thanks toObjects.hash()
, but this method allows passing a list of properties. If you want to ensureequals()
andhashCode()
are based on the same set of properties (which makes holding up their contract easier), you can just pass the same stored list of properties tokotlinEquals()
andkotlinHashCode()
and not worry about missing a property.It's also somewhat verbose, especially for larger objects, to write a property name twice, once to retrieve the property for
equals()
if usingkotlinEquals()
and once to retrieve the value forhashCode()
if usingObjects.hash()
.