Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.6-beta-2
-
Fix Version/s: 1.6-rc-1, 1.7-beta-1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Two equal instances of an @Immutable class should produce the same value when used as a map key. This is not the case, even though their hash codes are equal.
The last assert below fails, though it should succeed.
@Immutable final class Foo { String bar } foo1 = new Foo('bar') foo2 = new Foo('bar') assert foo1 == foo2 assert foo1.hashCode() == foo2.hashCode() fooMap = [(foo1) : 1] assert fooMap[foo1] == 1 assert fooMap[foo2] == 1 // Fails!!!
Changed equals(ImmutableClass other) to equals(Object other) which seems to fix the problem. I had assumed we could get away without this with bridging but appears not to be the case.