aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding hashcode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding hashcode " Watch "overriding hashcode " New topic
Author

overriding hashcode

Aneek Banerjee
Ranch Hand

Joined: Jun 20, 2012
Posts: 61

I have two objects lets say object 1 is t1 and object 2 is t2. I am assigning same integer value to this two objects,which is 10.Now I am confused how can I check if the both values are same for the object or not.And the second thing will the hash codes for these two objects will be same?(I believe not as ti.equals(t2) is giving me false).how can I check for the identical values here.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

When you're saying you're assigning the same integer value to two objects, what do you mean? Do you mean that the object has an integer member variable, and you're assigning the number to that?

If so, then you'd check for equality by comparing those member variables. And if you've got two different objects, and you haven't overridden hashCode(), then they will probably have different hash codes. If you have overridden hashCode(), then it depends on how you've done that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding hashcode