title: Are mutable hashmap keys a dangerous practice?
body: <p>Is it bad practice to use mutable objects as Hashmap keys?  What happens when you try to retrieve a value from a Hashmap using a key that has been modified enough to change its hashcode?</p>
  
  <p>For example, given</p>
  
  <pre><code>class Key
  {
      int a; //mutable field
      int b; //mutable field
  
      public int hashcode()
          return foo(a, b);
      // setters setA and setB omitted for brevity
  }
  </code></pre>
  
  <p>with code</p>
  
  <pre><code>HashMap&lt;Key, Value&gt; map = new HashMap&lt;Key, Value&gt;();
  
  Key key1 = new Key(0, 0);
  map.put(key1, value1); // value1 is an instance of Value
  
  key1.setA(5);
  key1.setB(10);
  </code></pre>
  
  <p>What happens if we now call <code>map.get(key1)</code>?  Is this safe or advisable?  Or is the behavior dependent on the language?</p>