/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hash tables such as those provided by
* {@link java.util.HashMap}.
* <p>
* The general contract of {@code hashCode} is:
* <ul>
* 1.<li>Whenever it is invoked on the same object more than once during
* an execution of a Java application, the {@code hashCode} method
* must consistently return the same integer, provided no information
* used in {@code equals} comparisons on the object is modified.
* This integer need not remain consistent from one execution of an
* application to another execution of the same application.
* 2. <li>If two objects are equal according to the {@code equals(Object)}
* method, then calling the {@code hashCode} method on each of
* the two objects must produce the same integer result.
* 3.<li>It is <em>not</em> required that if two objects are unequal
* according to the {@link java.lang.Object#equals(java.lang.Object)}
* method, then calling the {@code hashCode} method on each of the
* two objects must produce distinct integer results. However, the
* programmer should be aware that producing distinct integer results
* for unequal objects may improve the performance of hash tables.
* </ul>
* <p>
* As much as is reasonably practical, the hashCode method defined by
* class {@code Object} does return distinct integers for distinct
* objects. (This is typically implemented by converting the internal
* address of the object into an integer, but this implementation
* technique is not required by the
* Java<font size="-2"><sup>TM</sup></font> programming language.)
*
* @return a hash code value for this object.
* @see java.lang.Object#equals(java.lang.Object)
* @see java.lang.System#identityHashCode
*/
public native int hashCode();

2.如果两个对象通过equal方法判断是相同的话,那么他们通过hashCode方法的返回值一定是一样的

3.两个对象如果通equal方法的返回值是false,他们通过hashCode方法的返回值不一定是不同的;然而,我们应该意识到对于不相等的对象返回不同的hashCode值能够提高hash表的性能

JavaSE_坚持读源码_Object对象_Java1.7的更多相关文章

  1. JavaSE_坚持读源码_ClassLoader对象_Java1.7

    ClassLoader java.lang public abstract class ClassLoader extends Object //类加载器的责任就是加载类,说了跟没说一样 A clas ...

  2. JavaSE_坚持读源码_Class对象_Java1.7

    Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识.这项信息纪录了每个对象所属的类.虚拟机通常使用运行时类型信息选准正确方法去执行,用来保存这些类型信息的类是Class类 ...

  3. JavaSE_坚持读源码_ArrayList对象_Java1.7

    底层的数组对象 /** * The array buffer into which the elements of the ArrayList are stored. * The capacity o ...

  4. JavaSE_坚持读源码_HashSet对象_Java1.7

    对于 HashSet 而言,它是基于 HashMap 实现的,HashSet 底层采用 HashMap 来保存所有元素,因此 HashSet 的实现比较简单,查看 HashSet 的源代码,可以看到如 ...

  5. JavaSE_坚持读源码_String对象_Java1.7

    /** * Compares this string to the specified object. The result is {@code * true} if and only if the ...

  6. JavaSE_坚持读源码_HashMap对象_get_Java1.7

    当你从HashMap里面get时,你其实在干什么? /** * Returns the value to which the specified key is mapped, * or {@code ...

  7. JavaSE_坚持读源码_HashMap对象_put_Java1.7

    当你往HashMap里面put时,你其实在干什么? /** * Associates the specified value with the specified key in this map. * ...

  8. [一起读源码]走进C#并发队列ConcurrentQueue的内部世界

    决定从这篇文章开始,开一个读源码系列,不限制平台语言或工具,任何自己感兴趣的都会写.前几天碰到一个小问题又读了一遍ConcurrentQueue的源码,那就拿C#中比较常用的并发队列Concurren ...

  9. Java读源码之ReentrantLock(2)

    前言 本文是 ReentrantLock 源码的第二篇,第一篇主要介绍了公平锁非公平锁正常的加锁解锁流程,虽然表达能力有限不知道有没有讲清楚,本着不太监的原则,本文填补下第一篇中挖的坑. Java读源 ...

随机推荐

  1. Nginx 针对上游服务器缓存

    L:99 nginx缓存 : 定义存放缓存的载体 proxy_cache 指令 Syntax: proxy_cache zone | off; Default: proxy_cache off; Co ...

  2. Civil 3D 2017本地化中VBA程序移植到2018版中

    中国本地化包简直就是一块鸡肋, 但对于某些朋友来说还真离不了: 可惜中国本地化包的推出一直滞后, 在最新版软件出来后1年多, 本地化还不一定能够出来, 即使出来了, 也只能是购买了速博服务的用户才能得 ...

  3. chrome实用快捷键速记

    标签页和窗口快捷键 操作 快捷键 打开新窗口 Ctrl + n 无痕模式下打开新窗口 Ctrl + Shift + n 打开新的标签页,并跳转到该标签页 Ctrl + t 重新打开最后关闭的标签页,并 ...

  4. Maven添加Web.xml的方法

    当创建maven工厂时没有web.xml文件1.点击你的项目名称,进入到Myeclipse的-- Project Facets上,2.点击Dynamic Web Module 和下面的Java,将两个 ...

  5. Codeforces Round #443 Div. 1

    A:考虑每一位的改变情况,分为强制变为1.强制变为0.不变.反转四种,得到这个之后and一发or一发xor一发就行了. #include<iostream> #include<cst ...

  6. Redis——redis使用redis-dump,redis-load导出导入数据——【三】

    来源 https://www.cnblogs.com/dadonggg/p/8662455.html https://blog.csdn.net/chenxinchongcn/article/deta ...

  7. 基准对象object中的基础类型----列表 (四)

    object有如下子类: CLASSES object basestring str unicode buffer bytearray classmethod complex dict enumera ...

  8. python调用opencv库教程

    OpenCV安装pip install --upgrade setuptoolspip install numpy Matplotlibpip install opencv-python OpenCV ...

  9. POJ 3481 Double Queue

    平衡树.. 熟悉些fhq-Treap,为啥我在poj读入优化不能用啊 #include <iostream> #include <cstdio> #include <ct ...

  10. Python课程目录

    Python基础1 介绍.基本语法.流程控制 Python基础2 列表.字典.集合 Python基础3 基础3-函数