JDBCSupport - An easy to use, light-weight JDBC framework -
SCJP 6
SCJP 1.6
SCWCD 1.5 (Preparing...)
If we dont override the hash method then after we store our object in a map the only way we can get it back is using the same object reference. We cannot create a new object wich will be logically equal to our object in a map and find it in the map with this new object, if they equal but dont have the same hashcodes.Samrat Som wrote:This contract will only comes into play when we are overriding
But one question creeps in my mind . Though, I understand the previous statement ,but someway or somehow. There pops up a doubt. As according to the concept of Maps, the hashcode helps to find out the right bucket and then equals find out the right object referencing to it.
Even if we are not overriding the hash method , but internally the without overriden hash method should also adopt this kind of approach, mentioned theoretically.
[SCJP 6.0]
SCJP 1.6
SCWCD 1.5 (Preparing...)
Samrat Som wrote:Thanks Anastasia,
As my understanding goes , we need to override the hashcode function to extract the value ,which we can do it with the help of equals without considering the map data structure.
Map helps for quicker retrieval with the help od hashcode method with the help of equals.
I think hashcode implementation needs to be made mandatory rather than leaving it to decision of the programmer to override it.Otherwise , it beats the basic purpose of Map implementation.
Please add if I am wrong
[SCJP 6.0]
SCJP 1.6
SCWCD 1.5 (Preparing...)