Zambian Enquirer

Greenhorn
+ Follow
since Jan 30, 2003
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 Zambian Enquirer

write equals():I personally think it is very readable,
Thank you all for your replies.
I like this style of coding it! Neat.
Would someone like to elaborate on how overloading equals could break container classes?
I think I may have found one answer to my question here:
http://csis.pace.edu/~bergin/Java/OOJavaFAQ.html
If you overload equals you will have two different equals methods in your class. However, the compiler and libraries know about the inherited one and call it from a number of places--the HashMap add method, for example. You have to realize that these calls will still go to the inherited method and not to the overloaded one. If you want to write a method to check equality of objects rather than depend on the default behavior of the inherited equals method (reference equality), then you need to override equals, NOT overload it.
This seems to tie in with advice I have seen that one must also override hashCode when overriding equals.
Zambian
21 years ago
write equals():I personally think it is very readable,
Thank you all for your replies.
I like this style of coding it! Neat.
Would someone like to elaborate on how overloading equals could break container classes?
I think I may have found one answer to my question here:
http://csis.pace.edu/~bergin/Java/OOJavaFAQ.html
If you overload equals you will have two different equals methods in your class. However, the compiler and libraries know about the inherited one and call it from a number of places--the HashMap add method, for example. You have to realize that these calls will still go to the inherited method and not to the overloaded one. If you want to write a method to check equality of objects rather than depend on the default behavior of the inherited equals method (reference equality), then you need to override equals, NOT overload it.
This seems to tie in with advice I have seen that one must also override hashCode when overriding equals.
Zambian
21 years ago
Hello All,
I understand that overloading, as opposed to overriding, equals is poor form.
Can someone explain what the problems are with overloading equals?
Thanks,
Zambian Moose
21 years ago