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

  • Home
  • SEARCH
  • 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 8674467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:43:04+00:00 2026-06-12T19:43:04+00:00

There are two kinds equals methods? public boolean equals(Bigram b) { return b.first ==

  • 0

There are two kinds equals methods?

public boolean equals(Bigram b) {
    return b.first == first && b.second == second;
    }

@Override public boolean equals(Object o) {
    if (!(o instanceof Bigram))
        return false;
    Bigram b = (Bigram) o;
    return b.first == first && b.second == second;
}

compare with the 2 methods,when we want to override the equal method,why we need to define an equals method whose parameter is of type Object!

  • 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-12T19:43:05+00:00Added an answer on June 12, 2026 at 7:43 pm

    There is actually a good reason for this:

    • You need the equals(Object) method to override the superclass equals method in java.lang.Object
    • You often also want an overloaded equals(Bigram) method that handles the case where the compiler can prove that the type is Bigram at compile time. This improves performance by avoiding type checking/casting and gives you better type checking in your code.
    • Finally you may want to implement equals in a special way for testing with equality with objects that aren’t themselves an instance of Bigram. This should be used with care (do you really want something that is not a Bigram instance to be considered equal to a Bigram?), but it does have some valid applications (e.g. comparing the contents of different types of collection objects).

    Normally however it is best to implement them so that one method calls the other, e.g.:

    public boolean equals(Bigram b) {
        return b.first == first && b.second == second;
    }
    
    @Override public boolean equals(Object o) {
        if (!(o instanceof Bigram)) return false;
        return equals((Bigram)o);
    }
    

    This way is more concise and means that you only need to implement the equality testing logic once (Don’t Repeat Yourself!).

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

Sidebar

Related Questions

I would like someone to clarify something for me: There are two kinds of
As I known, there are two common kinds of practices to ensure the thread
Is there a way with IntelliJ Idea, to create two kinds of artifacts -
As far as I know there are two kinds of breadcrumbs. The static/hierarchy one
Intro In the application I 'm currently working on, there are two kinds of
From what I understand of ActionScript, there are two kinds of casts: var bar0:Bar
I am using a UIImagePicker in my viewController , and there are two kinds
There are two kind of type declaration mentioned in dojo documentation. They are data-dojo-type
I'm kind of torn between these two error-handling models: Create a boolean Error and
I have read a document that they say: In java there two types of

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.