Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
756 stars 55 forks source link

Auxilliary values #109

Open mads-b opened 2 years ago

mads-b commented 2 years ago

Records by default utilize all values in computation of equals and hashcode

Sometimes that's not what you want.

It's trivial to add a custom implementation of equals and hashcode to the records, but we could also introduce an annotation that could be assigned to record fields to result in custom equals and hashcode appearing in the Bean interface

What do you think? It's not a must-have, but rather useful

Randgalt commented 2 years ago

Can you give an short description of what that would look like? I don't see how an annotation could help with this.

mads-b commented 2 years ago

Mostly just me trying to find drop-in replacements to immutables features: https://immutables.github.io/immutable.html#auxiliary-attributes

If this is to be done, it would mean starting to generate equals, toString and hashCode as default methods in the generated Bean interface. These methods would then omit @Auxilliary-annotated fields from equals and hashCode, and omit @Redacted fields from toString.

This all might also be out of scope for this library, and in hindsight I might be better served making my own little interface-generator that created these three methods on demand..