Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:37:46+00:00 2026-06-08T22:37:46+00:00

Either in Javadoc as well as the code itself, Comparator interface defines: int compare(T

  • 0

Either in Javadoc as well as the code itself, Comparator interface defines:

 int compare(T o1, T o2);
 boolean equals(Object obj);

But then this gives no probs compilating:

 Comparator a = new Comparator() {      
     @Override public int compare(Object o1, Object o2) {
        //..
     }
 };

But this does:

 Comparator a = new Comparator() {      
     @Override public boolean equals(Object comparator) {
        //..
     }
 };

How its done for the interface for allowing us not to override method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:37:47+00:00Added an answer on June 8, 2026 at 10:37 pm

    First of all JavaDocs explain clearly that you should implements this method:

    Additionally, this method can return true only if the specified object is also a comparator and it imposes the same ordering as this comparator. Thus, comp1.equals(comp2)implies that sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2)) for every object reference o1 and o2.

    But later:

    Note that it is always safe not to override Object.equals(Object).

    How is it possible not to override equals(), even though it is part of an interface? Because this method is already implemented for each and every object in Java (in Object class).

    The declaration in the interface is there only to emphasise the importance of equals() with regards to Comparator by adding extra JavaDoc explanation.

    BTW if your comparator is stateless you should have only one instance of it – in which case the default equal() implementation is just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Either I'm going mad or the Code Analysis tab in Visual Studio has disappeared
c# offers a nice way to document your c#-code. But I don´t find any
Either i'm going nuts or nobody likes/liked this feature, but a long time ago
Either I've been staring at this code for way too long or I just
Either I don't understand the method getActualMaximum(int) or the field WEEK_OF_YEAR, or there's a
Possible Duplicate: Code documentation for delphi similar to javadoc or c# xml doc I
Either I am missing something or not understanding other posts/instructions. I am trying to
either I'm missing something or the ( patterns & practices Composite Application Guidance for
Either of these options would be fabulous: Send a bitmap image of the stage's
Either I missed some backlash or backlashing does not seem to work with too

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.