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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:12:06+00:00 2026-06-09T10:12:06+00:00

In the post What issues should be considered when overriding equals and hashCode in

  • 0

In the post What issues should be considered when overriding equals and hashCode in Java? one explains in great detail how to write proper equality method in Java using getClass to compare RUntime types of two objects we equate. I understand that the reason we do this is to make sure that if B extends A we want a.equals(b) = b.equals(a) (reflexivity).

It does provide a big limitation in my opinion. If you have a collection of objects A, inswert a few B objects as they are subclasses of A, then a.equals(b) is always false… Perhaps, at certain times, we should stick to the old instanceof operator to provide polymorphism and allow equality of subtypes? What are your thoughts?

  • 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-09T10:12:08+00:00Added an answer on June 9, 2026 at 10:12 am

    You need only look as far as java.util to see examples of where .equals() gets redefined to care only about interface. For example, java.util.List, where the relevant characteristics equality is defined, and the formula for calculating the hash code is explicitly documented.

    So to answer your question, yes — ignoring subtypes makes sense under certain circumstances. But I like Josh Bloch’s approach to this by making an interface the aspect of equivalence.

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

Sidebar

Related Questions

Refer original post here for a reference to the original issue. What plugin should
I have an express server that has a button that issues a POST which
Morning, simple stupid question. I have found post with similar issues but after reading
I'm having issues with my MVC3 vb.net application. When I try to post the
Don't be frightened by the length of the post, it should be pretty straightforward.
This is my first post here, so I should probably start by saying thankyou
I copied this code from another StackOverflow post. However, I am having some issues
According to this blog post the new messaging system should be accessible via the
I am having some issues creating the code which should show a button only
I am having issues with session in my java code. Upon submitting a form

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.