a guest Jan 12th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- MyKey key = new MyKey("shreyansh"); //assume hashCode=1234
- myHashMap.put(key, "value");
- // Below code will change the key hashCode() and equals()
- // but it's location is not changed.
- key.setName("jogi"); //assume new hashCode=7890
- //below will return null, because HashMap will try to look for key
- //in the same index as it was stored but since key is mutated,
- //there will be no match and it will return null.
- myHashMap.get(new MyKey("shreyansh"));
RAW Paste Data