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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:52:39+00:00 2026-06-08T11:52:39+00:00

According to Josh Bloch in Java: There is no way to extend an instantiable

  • 0

According to Josh Bloch in Java:

There is no way to extend an instantiable class and add a value
component while preserving the equals contract, unless you are willing
to forgo the benefits of object-oriented abstraction

So here ‘s my case I had a class Foo that had overridden equals() and hashcode() as implemented by Intellij Idea . Now I have another class FooChild that extends Foo and adds a couple more fields to ‘Foo`. Now FindBugs is complaining about FooChild:

Class doesn’t override equals in superclass This class extends a class
that defines an equals method and adds fields, but doesn’t define an
equals method itself. Thus, equality on instances of this class will
ignore the identity of the subclass and the added fields. Be sure this
is what is intended, and that you don’t need to override the equals
method. Even if you don’t need to override the equals method, consider
overriding it anyway to document the fact that the equals method for
the subclass just return the result of invoking super.equals(o).

My question is “What is meant by equality on instances of this class will
ignore the identity of the subclass
? I understand the part about ignoring the added fields since no equals() method has been written for them yet .

  • 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-08T11:52:40+00:00Added an answer on June 8, 2026 at 11:52 am

    What is meant by “equality on instances of this class will ignore the
    identity of the subclass ?”

    If class Foo has an equals() method, then FooChild inherits it, meaning that if you compare two instances of FooChild using equals(), the Foo.equals() method will be called.

    If FooChild has any data members, then it’s probably possible for two instances of FooChild to have the same values for members in their Foo parts, but different values for the members defined directly in the class. But the Foo.equals() method will only look at the members defined in Foo, and so would pronounce two such objects to be equals(), even though their FooChild parts are different.

    This is why you need to override equals() in FooChild.

    Now, what happens if you compare a Foo and a FooChild using equals(), when both classes have their own version of equals()? It depends which object you call equals() on, and it depends on how you implement the two equals() methods. Frankly, it’s a mess! That’s the meaning of the first quote, the one from Josh Bloch. It’s impossible to define these two equals() methods so they always do the right thing. Therefore, it’s best to avoid the situation where one value class (i.e., a class whose identity is tied up with the values of its member variables) extends another value class.

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

Sidebar

Related Questions

According to docs at http://code.google.com/p/minify/wiki/UriRewriting $min_serveOptions['rewriteCssUris'] = false; I should be able to add
According to Steffen's post this is an efficient way to generate random BOOL s
According to Microsoft ( link ), there are two ways to start a task:
According to C++11 9.1/7 (draft n3376) , a standard-layout class is a class that:
According to the MSDN article found at http://msdn.microsoft.com/en-us/library/wyk4d9cy.aspx the floating-point value .1 has no
According to my class notes, you can allocate an array in C++ like int
According to the Java standard the short and char types both use 2 bytes
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to
According to this question: Django on Google App Engine The easiest way to get
According to the information I could gather on .NET and Java execution environment, the

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.