Rob Prime wrote:
Although you are right that name.hashCode() would be better, name.length() is still a valid return value. After all, if two dogs have the same name, the length of their names is also the same.
True using the length of the name would work fine, but as the HashSet allows other object types to be stored, it is still potentially more efficient to make the hashCode return something that would be unique to the Dog class.
To be honest in the example code above it wouldn't make much difference, but I thought it was at least worth pointing out to Chhabra as it may prove useful in the future :-)