consoleau / kassava

This library provides some useful kotlin extension functions for implementing toString(), hashCode() and equals() without all of the boilerplate.
Apache License 2.0
115 stars 13 forks source link

Add kotlinHashCode method #5

Closed fdeitylink closed 4 years ago

fdeitylink commented 6 years ago

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().

jamesbassett commented 4 years ago

Thanks for this, and sorry for the wait. It's implemented now (https://github.com/consoleau/kassava/releases/tag/v2.1.0-rc.1)