Results 1 to 3 of 3
  1. #1
    finn is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default 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?

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    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.

  3. #3
    finn is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Use different comparator for SortedSet
    By linus_k in forum New To Java
    Replies: 0
    Last Post: 11-21-2008, 02:46 PM
  2. How to search with a Comparator
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:39 PM
  3. How to write your own Comparator
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:38 PM
  4. Using Comparable and Comparator interfaces
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. How to implements cryptation in a java
    By paul in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 05:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •