I have questions while implementing the hashmap for customized Employee class.
Overriding only
Hash()I have overridden only
hash()of employee class. so, I get same hashcode value for same objects. If I don't override equals(), then it would be fine right? since theequals() of object class compares the reference (where I got the same ref for equal objects). Anyhow, based on my logic, I will never get same hash for different emp objects. So it would be fine to leave theequals()?If we override both
Equals()andhashcode(), then we will always have unique value? so there won't be the possibility of getting Linkedlist in a single bucket location?When we override the equals(), in first line we will always give (this == o). In this case, Even after overriding the hashcode(), if i get same hashcode for 2 diff employee object, the first line will always gets satisfied if same hashcode returned. Then what is the use of having the remaining logic in equals()?