willy kocher

Greenhorn
+ Follow
since Aug 05, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by willy kocher


equals() method absolutely controls the determination of equivalence?



equals method always control the equivalence between two objects idenpedent of what the hashcode do, but remember a map use an int ( hashCode in this case)
to index their elements because of performance reasons..so a map needs a way to identify each object.. and the a hashcode is the solution, so if you do not overwrite your hashCode JVM will give a random and unique hascode for each object..
and so if you have two equals() object you probably would like to use the same one with 2 references right? if you do, you will follow the contract and overwrite the hashCode.
[ August 22, 2008: Message edited by: willy kocher ]
that only happens for compatibility reasons, maybe this could help you to understand:




is the same thing as the next code , right?



if that was not possible, you would not be allowed to write code with generics that supports legacy codes like 1.4 and vice-versa.