I read this sentence in K & B , can someone please elaborate this statement ?
"When using HashSet or LinkedHashSet, the objects you add to them must override hashCode(). If they don't override hashCode(), the default Object.hashCode() method will allow multiple objects that you might consider "meaningfully equal" to be added to your "no duplicates allowed" set.
Is it required that whenever we override the hashCode() we should also override equals() ?
If you want to use objects of any class as elements of a Set or key of a Map, you must override the hashCode and equals method. These two methods are used by these collections to find elements. The statement is opposite of what you are saying, it says that you must override the hashCode method when you override the equals method. Otherwise your equals method might not even get called because HashMap and HashSet use the hashCode method before the equals method to find out equal elements...