Hello ,
when going through tutorials in web i found this line :
"The Collection classes that implement interface Set or Map
expect the object or key object respectively to override equals " I need some clarification on the above statement .
Please let me know if the above is true ,because as far as i am concerned i could easily add Objects to a HashSet
without my Object overriding equals or hashcode .
There should be explanations about collections working incorrectly in some of these links: Odersky, Spoon and Venners (courtesy of Garrett Rowe), Angelika Langer and Joshua Bloch's Effective Java™ (you may be able to find a "sample chapter" from the 1st edition on the internet, which describes equals()).
Hi , After going through tutorials you mentioned , i got some idea when to overide equals and HashCode of an Object class .
I assume that , when we are using any Hashing type of Collection class and storing Custom objects under it then we need to override them , if not the searching is not done correctly .
Not really. I have many projects (or rather just some collection of code) which I use as quick examples for trying out various things. i.e. they are not meant for "serious" use.