Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
3.9
-
None
-
None
Description
Has it been considered to use lambdas to make it easier to write equals methods?
public boolean equals(final Object obj) { return new EqualsBuilder<MyClass>(this, obj) .append(it -> it.field) .appendSuper(super.equals(obj) .isEquals(); }
I know this is incompatible with the current EqualsBuilder so maybe a new class, or something like this would work instead:
public boolean equals(final Object obj) { return EqualsBuilder.with(this, obj) // with returns a generic type similar to EqualsBuilder .append(it -> it.field) .appendSuper(super.equals(obj) .isEquals(); }
It helps eliminate all the boilerplate code of checking object types and could even skip calling the lambdas if it already knew it was not equal.