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 8895731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:51:40+00:00 2026-06-14T23:51:40+00:00

Why is it considered better to use the default Object equals method in Java

  • 0

Why is it considered better to use the default Object equals method in Java and modify it so it will work for a specific class (by validating with instanceof and using type casting):

public boolean equals(Object otherObject)
{
   boolean isEqual = false;

   if ((otherObject != null) && (otherObject instanceof myClass))
      {
         myClass classObject = (myClass)otherObject;

         if (.....) //checking if equal
         {
            .....
}

instead of overloading it with a new equals method specific for each class that needs to use equals:

public boolean equals(myClass classObject)
  • 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-14T23:51:42+00:00Added an answer on June 14, 2026 at 11:51 pm

    The signature of Object.equals() is public boolean equals(Object). If you define a method public boolean equals(MyClass), you’re adding a new method, with a different signature, instead of overriding (or redefining, if you prefer) the Object.equals() method.

    Since all the collections call the Object.equals() method, your new method would never be called by anybody except your own code, and would thus be almost useless. For example, if you create a Set<MyClass>, it will consider that two instances are different, although your equals(MyClass) method considers them equal.

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

Sidebar

Related Questions

What is considered better style for an event definition: public event Action<object, double> OnNumberChanged;
What is considered better practice: <div class=clr></div> (Where clr is clear:both) or just simply:
Why is it considered better practice to use enum not static const bool in
Possible Duplicate: Why is Java Vector class considered obsolete or deprecated? Which type is
Is it considered better practice and/or more efficient to create a 'reset' function for
Which is considered better style? int set_int (int *source) { *source = 5; return
Can I represent ontology by using XML? Why it is considered better to represent
I was curious what is considered the better way to manage the reading and
Is it considered an acceptable practice to use Modules instead of Classes with Shared
Possible Duplicate: Are PHP short tags acceptable to use? Which is better to use,

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.