What is the hashcode of a primitive type, such as int?
for example, let's say num was an interger.
int hasCode = 0;
if (num != 0) {
hasCode = hasCode + num.hashCode();
}
Taken from the Integer.class
source code:
/**
* Returns a hash code for this {@code Integer}.
*
* @return a hash code value for this object, equal to the
* primitive {@code int} value represented by this
* {@code Integer} object.
*/
public int hashCode() {
return value;
}
Where value
is the value of the integer.