[
https://issues.apache.org/jira/browse/LANG-353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12528976
]
Henri Yandell commented on LANG-353:
------------------------------------
Sounds like you're suggesting:
* public boolean equals(Object obj) {
* if (obj == null) { return false; }
* if (obj == this) { return true; }
* if (obj.getClass() != getClass()) {
* return false;
* }
* MyClass rhs = (MyClass) obj;
* return new EqualsBuilder()
* .appendSuper(super.equals(obj))
* .append(field1, rhs.field1)
* .append(field2, rhs.field2)
* .append(field3, rhs.field3)
* .isEquals();
* }
Though an issue that we've come across with the builders is what to do with
classloaders. So you end up with:
* public boolean equals(Object obj) {
* if (obj == null) { return false; }
* if (obj == this) { return true; }
* if (!obj.getClass().getName().equals(getClass().getName()) {
* return false;
* }
* ...
Or maybe that doesn't matter because the rest of EqualsBuilder will be unhappy
anyway.
> Javadoc Example for EqualsBuilder is questionable
> -------------------------------------------------
>
> Key: LANG-353
> URL: https://issues.apache.org/jira/browse/LANG-353
> Project: Commons Lang
> Issue Type: Bug
> Reporter: Christoph Kutzinski
> Priority: Minor
> Fix For: 2.4
>
>
> The Javadoc example for the class EqualsBuilder ist questionable:
> public boolean equals(Object obj) {
> if (obj instanceof MyClass == false) {
> return false;
> }
> ...
> The implementation with instanceof lacks guarantees like equals-symmetry
> (see e.g. http://www.agiledeveloper.com/articles/equals062002.htm for a
> discussion of the issue)
> The example should be changed to use getClass(). Attention: the solution in
> the link above is incomplete as it doesn't check for null
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.