yangxu998 / guava-libraries

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

Key as Arraylist, cant be found, when softKey() is on #636

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Simple example:

private ConcurrentMap<Object, Object> map = new MapMaker().softKeys().makeMap();
private ArrayList<Object> mapKey = new ArrayList<Object>();

mapKey.add("key1");
mapKey.add(1111);
map.put(mapKey, "value1");
System.out.println("value from map: "+map.get(mapKey)+ ", hashCode of key 
"+mapKey.hashCode());

mapKey = new ArrayList<Object>();
mapKey.add("key1");
mapKey.add(1111);
System.out.println("value from map: "+map.get(mapKey)+ ", hashCode of key 
"+mapKey.hashCode());

What is the expected output? What do you see instead?
Expected value - "value1"
Instead of it, get() returns - null

What version of the product are you using? On what operating system?
guava verions = r09
OS - win7
java- 1.6.0_25

Please provide any additional information below.
Only occurs when softKey() is on

Original issue reported on code.google.com by bartlomi...@gmail.com on 1 Jun 2011 at 1:00

GoogleCodeExporter commented 9 years ago
MapMaker's documentation specifies that if soft or weak keys are used, it uses 
identity (==) for key equality. Similarly, it uses identity for value equality 
if soft or weak values are used.

Original comment by cgdec...@gmail.com on 1 Jun 2011 at 1:26

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