This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
Question taken from LearnKey MasterExam. Why is the set allowing duplicates, and showing the size as 2? I understand, it is because the equals() is not properly overridden, it doesn't take an Object. So, is the set allowing duplicate because of the equals() in Nearly class?
Thanks Ankit for your quick response. Is this what happens? calls equals() in the Nearly class. equals() and hashCode() are called before adding to HashSet. But here, the equals() called is of Object class(since Nearly class does not override equals() properly. So, n2 is added to the set. Please correct me if I'm wrong.