The following code results in the same hash code being generated for the two maps, any ideas?
import java.util.HashMap;
import java.util.Map;
public class Foo
{
@SuppressWarnings("unchecked")
public static void main (String[] args)
{
Map map;
map = new HashMap();
map.put("campaignId", 4770L);
map.put("location", "MINI_PROFILE");
map.put("active", "true");
map.put("lazy", true);
System.out.println(map.hashCode());
map = new HashMap();
map.put("campaignId", 4936L);
map.put("location", "MINI_PROFILE");
map.put("active", "true");
map.put("lazy", false);
System.out.println(map.hashCode());
}
}
The result is:
-1376467648
-1376467648
Simply changing the key names is enough to make the code generate two different hash codes.