how to override this hashCode method?
<p>as for the definition of Person:</p>

<pre><code>public class Person {
    private int id;
    private int characteristics;
    public boolean equals (Object obj) {
           if (obj == this) {
                 return true;
           }
           if (obj instanceof Person) {
                 if (id == ((Person) obj).id) {
                     return true;
                 } else if (characteristics == ((Person) obj).characteristics) {
                     return true;
                 }
           }
           return false;
    }
}
</code></pre>

<p>cause 2 <code>Person</code> objects <code>a</code> and <code>b</code> must have the identical hash code if <code>a.equals(b)</code> returns <code>true</code>, how should I implement the <code>hashCode</code> method?</p>

<p><strong>solution</strong></p>

<p>my <code>equals</code> method implementation is incorrect according to Java's equivalence protocol: <em>transitivity</em> is not satisfied: <code>a.id = 1</code>, <code>a.characteristic = 2</code>, <code>b.id = 1</code>, <code>b.characteristic = 3</code>, <code>c.id = 2</code>, <code>c.characteristic = 3</code>; <code>a.equals(b) == true</code>, <code>b.equals(c) == true</code>, but <code>a.equals(c) == false</code>.</p>
