And this will print out that the two objects are not equal. I can fix this problem by rewriting the equals method of Dimension . Now, objects of type ThreeDeeDimension won't return true when compared to objects of type Dimension . This is the point. It can turn a Hashtable lookup into a linear search.
Immutable classes make implementing a useful and safe hashCode easier.
In this case, you can use the data in the class to generate a hash value because that data will never change. Legal, useful and safe, but only because 'x' never changes. There are many details specified in each method's contract. You must implement these two methods together. You can rarely implement just one of them.