Java equals and hashcode

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thank you fr video

One question
Should we override both hashcode and equals method while working hashmap Or hashset
To eliminate duplicate objects adding to set

What happened if we only override equals method
Will set or map will allow duplicate

Plz reply
Thanks in advance

e.ch.vidyasagarkorada
Автор

are the hashcodes unique ? if yes, how objects are grouped in memory based on hash codes?

SHIVAM
Автор

Whatever you have explained that is perfectly fine but I have another doubt which is related to memory leak. When we don't implement the equals and hashcode it take from object class in that case too it gives us some unique code, So how GC is unable to clean up those unused objects when "get" method called internally then it definitely returns its hashcode.
But this whole scenario is a memory leak problem so please explain this.

anupkmr
Автор

sir can we provide any implementation for hashcode??

chetanchaudhari