java中Integer中的hashCode方法,是重写的,下面抄了部分Integer类的实现
public String toString() {
return String.valueOf(value);
}
/**
* Returns a hash code for this <code>Integer</code>.
*
* @return a hash code value for this object, equal to the
* primitive <code>int</code> value represented by this
* <code>Integer</code> object.
*/
public int hashCode() {
return value;
}
我们可以看到,实际上,Integer就是很简单的重写了一下toString和hashCode方法,就是返回本身的值。