title: Java StackOverflowError after putting ArrayList to HashMap
body: <p>Hello, can somebody explain to me why this block of code doesn't work?</p>
  
  <pre><code>ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;();
  list.add(list);
  
  HashMap&lt;Object, Integer&gt; map = new HashMap&lt;Object, Integer&gt;();
  map.put(list, 1);
  </code></pre>
  
  <p>After I put list to map, it throws StackOverFlowError.</p>
  
  <p>I know this code doesn't make any sense, I just want to know why it's not working.</p>
  
  <p>Thanks!</p>
  
  <p>Edit:</p>
  
  <p><p>stacktrace:</P></p>
  
  <pre><code>Exception in thread "main" java.lang.StackOverflowError
      at java.util.ArrayList.get(Unknown Source)
      at java.util.AbstractList$Itr.next(Unknown Source)
      at java.util.AbstractList.hashCode(Unknown Source)
      at java.util.AbstractList.hashCode(Unknown Source)
      ...
  </code></pre>