You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bruce Brouwer (Jira)" <ji...@apache.org> on 2020/06/03 21:04:00 UTC
[jira] [Created] (LANG-1551) EqualsBuilder with Lambdas
Bruce Brouwer created LANG-1551:
-----------------------------------
Summary: EqualsBuilder with Lambdas
Key: LANG-1551
URL: https://issues.apache.org/jira/browse/LANG-1551
Project: Commons Lang
Issue Type: Improvement
Components: lang.builder.*
Affects Versions: 3.9
Reporter: Bruce Brouwer
Has it been considered to use lambdas to make it easier to write equals methods?
{code:java}
public boolean equals(final Object obj) {
return new EqualsBuilder<MyClass>(this, obj)
.append(it -> it.field)
.appendSuper(super.equals(obj)
.isEquals();
}{code}
I know this is incompatible with the current {{EqualsBuilder}} so maybe a new class, or something like this would work instead:
{code:java}
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();
}{code}
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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)