HashCode for Generic objects in Java
<p>I understand the idea of hashCode and why it's needed. However I'm confused about how hashCode is calculated for a Generic object. So here's my questions. If I've a String, I'd probably use the following function to calculate the hashCode,</p>

<pre><code>int hash = 7;
for (int i = 0; i &lt; strlen; i++) {
    hash = hash*31 + charAt(i);
}
</code></pre>

<p>But say I've the following object,</p>

<pre><code>class Node&lt;K, V&gt; {

        private K key;
        private V value;
        private Node&lt;K, V&gt; next;
}
</code></pre>

<p>My IDE generates an automated hashCode function for this,</p>

<pre><code>@Override
public int hashCode() {
      int result = key != null ? key.hashCode() : 0;
      result = 31 * result + (value != null ? value.hashCode() : 0);
      result = 31 * result + (next != null ? next.hashCode() : 0);
      return result;
}
</code></pre>

<p>My questions is since Key and Value are generic,what does <code>key.hashCode()</code> do?
How does this method work?</p>