Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Beginning Java
Overriding the equlas method
Dounia Kchiere
Greenhorn
Posts: 9
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
I would like to know how I can override the equals method( to compare two objects) in a class that implements a Comparator..
Thank you so much for your help,
Dounia
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What specifically is giving you a problem? Is this an interview or homework question?
Please, nobody just give the very obvious answer.
[Jess in Action]
[AskingGoodQuestions]
Kaydell Leavitt
Ranch Hand
Posts: 694
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dear Sherriff:
You are in a beginner's forum. Maybe
you should
go to the intermediate or advanced forum.
I think that this is the answer to the question:
public boolean equals(Object other) {
return compare(this, other);
}
I'm assuming that the compare method of the comparator interface is already implemented.
-- Kaydell
[ November 25, 2006: Message edited by: Kaydell Leavitt ]
Jeroen T Wenting
Ranch Hand
Posts: 1847
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don't do that. The compare method will likely call equals (or at least can), causing an infinite loop
And remember to always override hashCode() when you override equals(), one without the other is asking for trouble.
42
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Why two threads accessing synchronized method at the same time
Garbage collection problem
Abstract Factory Pattern Vs Factory Pattern
hexFormat in UUID Generation
Zip Directory Recursively
More...