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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:32:24+00:00 2026-06-13T03:32:24+00:00

I have an issue where I am trying to use test the equals method

  • 0

I have an issue where I am trying to use test the equals method of a superclass using objects of a subclass:

My superclass is:

public class Excluded_DateTime implements Serializable {

private Date fromDate;   
private Time fromTime;
private Date toDate;   
private Time toTime;
private Valid active;

And the subclass differs by having an identifier as a key:

public class Classifier_Excluded_DateTime implements Serializable {

private Integer classifierExcludedDateTimeNo;    
private Excluded_DateTime classifierExcludedDateTime;   

So I want to test the equality of Classifier_Excluded_DateTime objects without using the field classifierExcludedDateTimeNo.

But what I am finding is that the equals method of the superclass is never called.

The NetBeans generated equals and hashCode methods of the superclass are as follows:

@Override
    public int hashCode() {        
        int hash = 7;
        hash = 23 * hash + (this.fromDate != null ? this.fromDate.hashCode() : 0);
        hash = 23 * hash + (this.fromTime != null ? this.fromTime.hashCode() : 0);
        hash = 23 * hash + (this.toDate != null ? this.toDate.hashCode() : 0);
        hash = 23 * hash + (this.toTime != null ? this.toTime.hashCode() : 0);
        hash = 23 * hash + (this.active != null ? this.active.hashCode() : 0);
        return hash;
    }

@Override
public boolean equals(Object obj) {        
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final Excluded_DateTime other = (Excluded_DateTime) obj;
    if (this.fromDate != other.fromDate && (this.fromDate == null || !this.fromDate.equals(other.fromDate))) {
        return false;
    }
    if (this.fromTime != other.fromTime && (this.fromTime == null || !this.fromTime.equals(other.fromTime))) {
        return false;
    }
    if (this.toDate != other.toDate && (this.toDate == null || !this.toDate.equals(other.toDate))) {
        return false;
    }
    if (this.toTime != other.toTime && (this.toTime == null || !this.toTime.equals(other.toTime))) {
        return false;
    }
    if (this.active != other.active) {
        return false;
    }
    return true;
}

And those of the subclass as follows:

@Override
public int hashCode() {                
    int hash = 7;
    hash = 79 * hash + (this.getClassifierExcludedDateTimeNo() != null ? this.getClassifierExcludedDateTimeNo().hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object obj) {        
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    if (! super.equals(obj)) {            
        return false;
    }
    final Classifier_Excluded_DateTime other = (Classifier_Excluded_DateTime) obj;   

    if (this.getClassifierExcludedDateTimeNo() != other.getClassifierExcludedDateTimeNo() && (this.getClassifierExcludedDateTimeNo() == null || !this.classifierExcludedDateTimeNo.equals(other.ClassifierExcludedDateTimeNo))) {            
        return false;
    } 
    return true;
}

Can I do what I’m trying to do by amending these methods of either class?

I am trying to test whether two instance of Classifier_Excluded_DateTime are the same without including the field classifierExcludedDateTimeNo in the comparison.

  • 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-13T03:32:25+00:00Added an answer on June 13, 2026 at 3:32 am

    You are not declaring Classifier_Excluded_DateTime as a subclass of Excluded_DateTime. To do that, you would need to say:

    public class Classifier_Excluded_DateTime extends Excluded_DateTime {
    

    Right now, it seems more like you are treating Excluded_DateTime as a kind of delegate of Classifier_Excluded_DateTime, as you have a member instance variable inside of Classifier_Excluded_DateTime that is of type Excluded_DateTime (the place where you say private Excluded_DateTime classifierExcludedDateTime;). I don’t think that’s your intent, since you are talking about subclasses and superclasses in your post.

    (Update: removed error where I thought there was not an explicit super.equals() call).

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

Sidebar

Related Questions

I'm trying to use fancybox to display 2 SWF videos. I have the issue
I have an issue. I use this code: var test='test'; $('#tip').delay(1000).html(test); That doesn't work,
I'm using EF 5 and am trying to use the ShouldLog method to determine
I have this issue trying to get all the text nodes in an HTML
I have ran into an interesting issue while trying to create a more usable
I have an issue with psql. I am trying to select the records from
I have an issue where in, I am trying to add copyrights message in
I have an issue with a for loop in java. I'm trying to do
can anyone help? I have an issue with linq2sql and trying to Attach (update)
I have an encoding issue in perl when trying to pull back global addresses

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.