Commit 48b9a9b
committed
#1858: restrict collection.Immutable equals to fellow Immutable wrappers
Delegating equals() to the inner collection produced asymmetric equality
when compared with a plain list: 'wrapper.equals(list)' was true (via
delegation) but 'list.equals(wrapper)' was false because Immutable is a
Collection, not a List. The Collection interface adds no stipulations to
Object.equals, so restricting equals() to other Immutable instances
keeps the wrapper symmetric with any plain List/Set while still allowing
two wrappers of equal content to compare equal. hashCode() keeps
delegating to the inner collection — equal objects still have equal
hashCodes; unequal objects may share a hash, which is permitted.1 parent 2a86f62 commit 48b9a9b
1 file changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
0 commit comments