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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:17:30+00:00 2026-06-11T21:17:30+00:00

I have a problem with Class.getSuperclass(). I want to generate a hierarchy of classes

  • 0

I have a problem with Class.getSuperclass(). I want to generate a hierarchy of classes where each child, after comparing its attributes to the other class, passes on the equals request to the parent. With this approach I need to stop calling super.equals when I have reached the level above Object since Object does an isSame comparison and that is not what I want.

Suppose I have this hierarchy:

class Child extends Parent {
    ...
    public boolean equals(Object other) {
        ... compare my attributes to other, if everything matches:
        if (myImmediateSuperIsObject()) {
           return true;
        } else {
           return super.equals(other)
        }
    }
}



class Parent extends Object {
    public boolean equals(Object other) {
        ... compare my attributes to other, if everything matches:
        if (myImmediateSuperIsObject()) {
           return true;
        } else {
           return super.equals(other)
        }
    }
}

The problem is the myImmediateSuperIsObject pseudo call. How to write it?
When Parent.equals is called from Child.equals, then within Parent, this.getClass().getSuperclass() is not Object, but Parent. That is because when calling getSuperclass(), we are always starting at the class of the instance, which is Child. So I can build the entire hierarchy by recursively calling getSuperclass until I get null, but how do I determine if I’m just above Object in my chain of equals calls?

To reiterate, all this is only an issue because I need to generate the class hierarchy. If I were to write this manually, I would of course know that I am extending object and stop calling super.equals().

Any idea?

Best regards,
Dietrich

  • 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-11T21:17:31+00:00Added an answer on June 11, 2026 at 9:17 pm

    Since you’re comparing properties in your object hierarchy, have you considered using EqualsBuilder.reflectionEquals from Commons Lang?

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

Sidebar

Related Questions

Hi i have problem with a class i want to pass in an intent
I have problem updating attributes in a python class, I give a small example.
I have a problem with a class template. I want the private data in
I have problem with mongomapper associations. I have one class names User and other
I have problem with not members of a class functions. I want to use
I have a problem With Entity Framework and TPC Inheritance With Self-Referencing Child Class.
Good day, I have the following problem: class B extends class A and methods
I have a design problem: Question class: have a question and answer (String) TextQuestion
I have a problem with ViewHolder class. I use ViewHolder to improve my List
I have problem organizing my unittest based class test for family of tests. For

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.