Now we are discussing about the implementation of he hashcode(). hashcode () is simply use for the comparison. we have a code for the hashCode().class HasHash {
public int a;
HasHash(int xVal) {
a = aVal;
}
public boolean equals(Object o) {
HasHash h = (HasHash) o; // Don\'t try at home without
// instanceof test
if (h.a == this.a) {
return true;
} else {
return false;
}
}
public int hashCode() {
return (a * 22);
}
}
Because the equals() method considers two objects equal if they have the same a value, we have to be sure that objects with the same a value will return identical hashcodes.
By:umang
Date:2013-03-09 00:00:00
Overriding hashCode() and equals()
What It Means if we Don\'t Override equals()
Implementing an equals() Method
So What Do we Do with a Collection?
Key Interfaces and Classes of the Collections Framework
Overview of Memory Management and Garbage Collection
Overview of Java\'s Garbage Collector
When Does the Garbage Collector Run?
How Does the Garbage Collector Work?
Reassigning a Reference Variable