HashCode详解

  在分析Object.java发现如下的方法:

public native int hashCode();

  本着穷究的目的,去找相关的资料分析为什么Object.java为什么有这个原生的HashCode方法。

二. 分析

  (1)HashCode是什么?

               HashCode:根据Hash算法依据对象的某些属性(内存地址等)生成的一个int类型的数字,让同一个类的对象按照自己不同的特征尽量的有不同的HashCode。

      (2)Object.java为什么要实现hashCode方法?

    Object.java对象是一切对象的基类,实现该方法,可以让Hash数据结构(如HashTable,HashMap,HashSet)操作对象,Hash数据结构使用HashCode确认在该数据结构中的对象的存储位置。

               This method is supported for the benefit of hash tables such as those provided by {@link java.util.HashMap}.

      (3)Hash数据结构是什么?

               Hash数据结构是一种特殊的数据结构,使用Hash算法实现,可以快速地定位查找的对象,提高查询效率。

原文地址:https://www.cnblogs.com/knsbyoo/p/9032654.html