Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.3.2
-
None
Description
Remove the need for boilerplate code still necessary with EqualsBuilder. Instead of checking for instanceOf or equality checks, it would be nice to be able to write this:
public boolean equals(final Object obj) { return EqualsBuilder.test(this, obj).append(this.id, o -> o.id).isEquals(); }
I think this could generally work with a subclass of EqualsBuilder with a generic type, like this:
public class LambdaEqualsBuilder<T> extends EqualsBuilder { private final T obj; public LambdaEqualsBuilder(final T _this, final Object obj) { if (_this != obj && !_this.getClass().isInstance(obj)) { appendSuper(false); this.obj = null; } else { this.obj = (T) obj; } } public <P> LambdaEqualsBuilder<T> append(final P a, final Function<T, P> b) { if (isEquals()) { return (LambdaEqualsBuilder<T>) append(a, b.apply(obj)); } return this; } // This might actually go in EqualsBuilder itself public static <E> LambdaEqualsBuilder<E> test(final E _this, final Object _that) { return new LambdaEqualsBuilder<E>(_this, _that); } }
Attachments
Issue Links
- is related to
-
LANG-923 JDK 1.8 Changes
- Closed