This is a discussion on Difference between hashcode() and equals()... within the Java forums, part of the Programming Talk category; I have tried so many times to find the difference...but not getting a satisfactory explanation.... can anybody explain with a ...
|
|||||||
|
|||
|
hashcode is an integer number which is provide to each object by jvm note that this is not address of object but for convencing internally they use
equals() is used to compare the objects it returns boolean value if any doubt then pls ask |
|
|||
|
Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.
It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|