1 Object中定义的hashCode() public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap. The general contract of hashCode is: Whenever it is invoked on the same…
hashCode和equals方法是Object类的相关方法,而所有的类都是直接或间接的继承于Object类而存在的,为此,所有的类中都存在着hashCode和equals.通过翻看Object类的相关源码,发现其hashCode的实现方式如下: public native int hashCode(); 从中可以看出,hashCode的实现是一个本地方法,并且其返回了一个int型的值.很多人都认为在默认情况下,hashCode返回的就是对象的存储地址,事实上这样的看法是不全面的,确实有…