Reason for Override!
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Strings and wrappers,Hashtable,HashMap override equals(),hashcode()
What is the reason for Override these methods?
What is the reason for Override these methods?
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
equals and hashcode are methods from Object. Collection famework class like HashTable, TreeSet, ... when you put objects in to collection class as mentioned before. you need overriden equals and hashcode methods. If not they won't do the thing like you thought.
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi
"Strings and wrappers,Hashtable,HashMap override equals(),hashcode()
What is the reason for Override these methods? "
we have to reframe the sentence :
Strings and wrappers over-ride the equals and hascode method
and HashMap and HashTable require these methods to be over-ridden by the class ( only if calss is user-defined not in case of Strings and wrappers as they already over-ride them )whose objects we are going to add them beacuse Map stores key-value pairs , to access them or retrieve them , addreses of keys ( which we get thru hashcode ) and their corresponding values ( which we get thru equals method)so over-ridding is must .
Now the imp thing why in Strings and Wrapper classes these methods were overidden ? Because : Mother class Object doesnt provide the required implementation of equals method i.e to compare two objects thru thier states or say values.
Hope this makes sense.
Thanku
Vishal..
"Strings and wrappers,Hashtable,HashMap override equals(),hashcode()
What is the reason for Override these methods? "
we have to reframe the sentence :
Strings and wrappers over-ride the equals and hascode method
and HashMap and HashTable require these methods to be over-ridden by the class ( only if calss is user-defined not in case of Strings and wrappers as they already over-ride them )whose objects we are going to add them beacuse Map stores key-value pairs , to access them or retrieve them , addreses of keys ( which we get thru hashcode ) and their corresponding values ( which we get thru equals method)so over-ridding is must .
Now the imp thing why in Strings and Wrapper classes these methods were overidden ? Because : Mother class Object doesnt provide the required implementation of equals method i.e to compare two objects thru thier states or say values.
Hope this makes sense.
Thanku
Vishal..
| keep an eye out for scorpions and black widows. But the tiny ads are safe. Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |








