yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

ImmutableMap may not be using proper equals () method #682

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a `Map <Transcription, File> m`. Transcription is user defined, with a 
user defined `equals ()` method. When I define a new Transcription t, and call 
m.get (t), it works properly, but when I use `ImmutableMap.copyOf (m).get (t)`, 
it returns `null`.

Original issue reported on code.google.com by capidepa...@gmail.com on 10 Aug 2011 at 5:45

GoogleCodeExporter commented 9 years ago
I also get false if I run:

`ImmutableMap.copyOf (m).keySet ().contains (t);`

Original comment by capidepa...@gmail.com on 10 Aug 2011 at 5:47

GoogleCodeExporter commented 9 years ago
My best guess is that you forgot to implement the hashCode() method. When you 
use a Map / Set, the equals contract *mandates* that you should override 
hashCode() when you override equals().

Original comment by nev...@gmail.com on 10 Aug 2011 at 9:38

GoogleCodeExporter commented 9 years ago
That seems most likely. Closing unless/until we hear from 'capidepa...' again

Original comment by kevin...@gmail.com on 11 Aug 2011 at 1:51

GoogleCodeExporter commented 9 years ago
my bad. I didn't know you had to set hashCode() too.

Original comment by capidepa...@gmail.com on 11 Aug 2011 at 2:50

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09