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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:35:41+00:00 2026-06-15T05:35:41+00:00

Having Node abstract class which Cell extends him . In Cell I implemented public

  • 0

Having Node abstract class which Cell extends him .

In Cell I implemented public boolean equals(Node cmpCell) . I created Set<Node> closeList = new HashSet<Node>(); and when I execute closeList.contains((Cell) node) I debugged it and detect that it utterly ignores Cell equals I implemented . What I did wrong ?

Edit :

I changed in Cell to

@Override
public boolean equals(Object cmpCell)

and still closeList.contains((Cell) node) doesn’t using the above override .

2nd Edit :

In Cell class there is 2 members –

int colIndex ;
int rowIndex ;

the equals override just compare them to that both members of the 2nd class , I think it would be better I use HashMap<K, V> but still I would be glade to know how the hashCode should be looks like in such case ?

  • 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-15T05:35:42+00:00Added an answer on June 15, 2026 at 5:35 am
    public boolean equals(Node cmpCell)
    

    This is not a valid override. The syntax of equals method of Object class is: –

    public boolean equals(Object)
    

    And yes, as pointed out by @JonSkeet in comment, whenever you are overriding equals method, also remember to override hashCode method to follow the contract of equals and hashCode. Because if you don’t do that, then even if your equals method shows evaluates your instances as equal, the default hashCode implementation in Object class will generate different hashCodes for them, and hence they won’t be equal.

    Also, ensure that, while calculating hashcode, you consider only those attributes, that you used to compare your instances in equals method. Else, again you will get incorrect result.

    In addition to that, if you are using any IDE like Eclipse, it generates a very nicely overridden and compatible equals and hashCode method for you. You should be better using them.
    You need to right-click on your class, go to source and select Generate equals and hashCode method.

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

Sidebar

Related Questions

I am having a real headache trying to set a node's local position to
There is a directed graph having a single designated node called root from which
Im having a problem with python.. I have a binary tree node type: class
i have an ASP tree view having a Node so now, i have to
I want to get to the exact node having this text: 'Company'. Once I
Having construction in a form: struct Node { Node():left_(nullptr), right_(nullptr) { } int id_;
I am having a problem with selecting a certain child node. What I want
I'm having fun with a change to a content type field (from a node
I'm about to batch update every node in my database. Having made a recent
I am having xml with following structure <ruleDefinition appId=3 customerId = acf> <node alias=element1

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.