Results 1 to 3 of 3
- 05-14-2010, 05:42 PM #1
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
implements java.util.Comparator<type>
Do understand that the implementation of an interface, then all the methods in the interface also have to be implemented , that is coded in the class that implements the interface. If not all the methods in the interface are coded in the class, the class will then be abstract.
If we implement the Comparator interface as it has (according to API) two methods: compare () and equals (). According to the book "Programming in Java", we dont need to code both methods. In the book it is a class witch implements Comparator, but they implement/code only the compare method, and they do not implement/code the equals method. I thought this class then will be abstract, but this is not so.
Why do we not need to code both methodes in the Comparator interface?
- 05-14-2010, 06:35 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
equals() is implemented by Java Object class. Therefore, every other Java object already has equals() implemented. compare(), on the other hand, is a different story.
- 05-14-2010, 06:58 PM #3
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Use different comparator for SortedSet
By linus_k in forum New To JavaReplies: 0Last Post: 11-21-2008, 02:46 PM -
How to search with a Comparator
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:39 PM -
How to write your own Comparator
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:38 PM -
Using Comparable and Comparator interfaces
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
How to implements cryptation in a java
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks