previous | start | next

## Hashing

- Must be compatible with `equals`:
  if `x.equals(y)`, then `x.hashCode() == y.hashCode()`
- `Object.hashCode` hashes memory address
- NOT compatible with redefined `equals`
- Remedy: Hash all fields and combine codes:

      public class Employee

      {

         public int hashCode()

         {

            return name.hashCode()

               + new Double(salary).hashCode();

         }

         ...

      }

previous | start | next