分析Java 8中 Objects 类源码

【1.JDK底层源码剖析】1.1 Objects常用方法的源码剖析 本文剖析了 Java 11 中 java.util.Objects 工具类的常用方法源码实现。该工具类提供了一系列空指针安全的静态方法,包括对象比较(equals、deepEquals)、哈希计算(hashCode、hash)、字符串转换(toString)以及空值检查(requireNonNull系列、isNull、nonNull)等。这些方法设计精巧,通过内部空指针处理避免了外部冗长的判空逻辑,提高了代码健壮性和可读性。特别值得注意的是,requireNonNull系列方法实现了快速失败机制,而hash 阅读详情

Objects 类位于 java.util 包下,自 JDK 1.7 版本新增的,它是一个 final 类,不能被继承,且构造函数是 private 的,不能被实例化,它提供了一系列操作Object对象的静态方法,通常会被当做工具类去使用,其类定义如下:

<pre class="hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public final class Objects {}

Objects 类在 jdk 源码中应用很广泛,通过 Intellij Idea 搜索一下在 rt.jar 包中的应用,部分截图如下:

::: hljs-center

:::

从上面的搜索结果可以看出,在 jdk 1.8 版本中,大概有 366 处使用了 Objects 类的相关方法,下面结合具体的源码来分析一下。

1、构造函数

Objects 类不能被实例化,其构造函数是私有的,实现如下:

<pre class="prettyprint hljs cpp" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">private Objects() {
    throw new AssertionError("No java.util.Objects instances for you!");
}

2、方法

Objects 类提供的静态方法大致可以分为以下的几类:

  • equals :比较两个对象是否相同
  • hash :获取对象的哈希值;
  • toString :将对象转换为字符串
  • requireNonNull :要求对象不为空
  • isNull :判断对象是否为空
  • nonNull :判断对象不为空

具体可以通过下面的结构图来看看这些方法:

::: hljs-center

:::

2.1 equals 方法

equals() 方法主要用于比较两个指定的对象是否相同,定义如下:

<pre class="prettyprint hljs delphi" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static boolean equals(Object a, Object b) {
    return (a == b) || (a != null && a.equals(b));
}

除了 equals() 方法外,还有一个 deepEquals() 方法,该方法用于比较两个对象是否完全相同,可用于比较两个数组对象是否相同,其定义如下:

<pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static boolean deepEquals(Object a, Object b) {
    if (a == b)
        return true;
    else if (a == null || b == null)
        return false;
    else
        // 对数组元素进行比较
        return Arrays.deepEquals0(a, b);
}

在比较数组对象是否相同时,具体调用的是 Arrays.deepEquals0() 方法,其实现如下:

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">static boolean deepEquals0(Object e1, Object e2) {
    assert e1 != null;
    boolean eq;
    if (e1 instanceof Object[] && e2 instanceof Object[])
        eq = deepEquals ((Object[]) e1, (Object[]) e2);
    else if (e1 instanceof byte[] && e2 instanceof byte[])
        eq = equals((byte[]) e1, (byte[]) e2);
    else if (e1 instanceof short[] && e2 instanceof short[])
        eq = equals((short[]) e1, (short[]) e2);
    else if (e1 instanceof int[] && e2 instanceof int[])
        eq = equals((int[]) e1, (int[]) e2);
    else if (e1 instanceof long[] && e2 instanceof long[])
        eq = equals((long[]) e1, (long[]) e2);
    else if (e1 instanceof char[] && e2 instanceof char[])
        eq = equals((char[]) e1, (char[]) e2);
    else if (e1 instanceof float[] && e2 instanceof float[])
        eq = equals((float[]) e1, (float[]) e2);
    else if (e1 instanceof double[] && e2 instanceof double[])
        eq = equals((double[]) e1, (double[]) e2);
    else if (e1 instanceof boolean[] && e2 instanceof boolean[])
        eq = equals((boolean[]) e1, (boolean[]) e2);
    else
        // 如果不是数组类型,则直接使用 Object.equals() 方法比较
        eq = e1.equals(e2);
    return eq;
}

上面的方法实现中,会逐个比较数组中的元素是否相同,如果都相同,则两个数组相同。

2.2 hashCode 方法

hashCode() 方法用于获取对象的哈希值,其实现如下:

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static int hashCode(Object o) {
    // 如果对象不为空,则调用 Object 的 hashCode() 方法
    // 否则直接返回 0
    return o != null ? o.hashCode() : 0;
}

除了可以获取单个对象的哈希值外, Objects 还提供了可以获取多个对象的哈希值,即 hash() 方法,如下:

<pre class="prettyprint hljs cpp" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static int hash(Object... values) {
    return Arrays.hashCode(values);
}

该方法的参数为可变长参数,具体实现是调用 Arrays.hashCode 方法,其源码如下:

<pre class="prettyprint hljs groovy" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static int hashCode(Object a[]) {
    if (a == null)
        return 0;

    int result = 1;

    for (Object element : a)
        result = 31 * result + (element == null ? 0 : element.hashCode());

    return result;
}

从上面的实现可以看出,数组元素的哈希值是所有元素的哈希值经过一定变换后的和。

2.3 toString 方法

toString() 方法就是将对象转换为字符串,如果对象为 null ,则会直接返回 null 字符串,其实现如下:

<pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static String toString(Object o) {
    return String.valueOf(o);
}

public static String toString(Object o, String nullDefault) {
    // 如果对象为null,则可以返回一个默认值
    return (o != null) ? o.toString() : nullDefault;
}

toString() 方法具体实现调用的是 String.valueOf() 方法,而 String.valueOf() 方法又会调用 Object.toString() 方法,其源码如下:

<pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static String valueOf(Object obj) {
    return (obj == null) ? "null" : obj.toString();
}

2.4 requireNonNull 方法

requireNonNull() 方法用于判定参数对象是否为空,如果对象为空,则会抛出空指针异常,其实现如下:

<pre class="prettyprint hljs cs" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static <T> T requireNonNull(T obj) {
    // 直接抛出空指针异常
    if (obj == null)
        throw new NullPointerException();
    return obj;
}

public static <T> T requireNonNull(T obj, String message) {
    // 抛出指定信息的空指针异常
    if (obj == null)
        throw new NullPointerException(message);
    return obj;
}

public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) {
    // 通过一个 Supplier 来获取空指针异常信息
    if (obj == null)
        throw new NullPointerException(messageSupplier.get());
    return obj;
}

requireNonNull() 有3个重载方法,可以指定抛出空指针异常时的信息,对于第三个方法,可以传入一个 Supplier ,在对象为空时,动态的构建空指针异常信息,如果一个方法要求参数不能为空,那么就可以直接使用该方法对参数进行空校验。

2.5 isNull 方法

isNull() 方法判定对象为空,其实现比较简单,如下:

<pre class="hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static boolean isNull(Object obj) {
    return obj == null;
}

在平时的编程过程中,如果需要判断对象等于 null 时,也可以使用 Objects.isNull() 方法替代。

2.6 nonNull 方法

和 isNull() 方法相反, nonNull() 方法用于判断对象不为空,其实现也比较简单,如下:

<pre class="hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 0.75em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public static boolean nonNull(Object obj) {
    return obj != null;
}

整个 Objects 类的源码还是比较少的,主要作为一个工具类去使用,对于平时的空判断、非空判断或者参数校验,都可以尝试使用 Objects 类替代,可以使代码更加简洁。

DeepSeek API调用太复杂?OneAPI一站式聚合解决方案 本文介绍了OneAPI如何作为一站式聚合解决方案,简化DeepSeek API的调用流程。通过统一接口、智能路由和模型映射等核心功能,OneAPI大幅降低了多API适配的复杂性,提升开发效率。文章还提供了详细的部署指南和高阶使用技巧,帮助开发者快速实现API聚合管理。 阅读详情

相关推荐

2024从零开始使用VSCode编程(静态页面制作篇)HTML+CSS+JS阶段

VSCode第一个前端静态页面的编写

ssrsrrn的博客 9590

JSON.stringify() 格式化 输出log

调试程序的过程中,我们打印一个日志: console.log(object);,其中object是任意的一个json对象。 在控制台就会看到[object object],而看不到具体的内容。 我们可以这样做: console.log(JSON.stringify(object)); 控制台输出: {"name":"zhangsan","age":"18"} 如果object 如果内...

weixin_30662109的博客 482

PTA 编程题(C语言)-- 然后是几点

PTA 编程题(C语言)-- 然后是几点

LCCprogrammer 5074

alert弹出[object Object],怎么进一步查看值

bianweiqu的博客 2万+

Android Qcom Display学习(十一)

该系列文章总目录链接与各部分简介:本章主要是基于MIPI Payload传输接口的学习,包括Generic和DCS的接口不同。底层都是基于去封装的,下面第一部分调用原生接口,第二部分分析高通是如何进行读写操作的。

Android驱动开发 3179

结合 Conda 手动安装 RepeatMasker

RepeatMasker 是一个广泛使用的生物信息学工具,用于识别和屏蔽(mask)基因组序列中的 重复序列(repeats) 。在使用过程中需要调用重复序列数据库(Repbase 和 Dfam),如果使用Conda安装的话会出现许多问题,因此推荐手动安装。在此记录我手动安装RepeatMasker的流程,希望对各位同学有所帮助。

m0_65437087的博客 2534

JS 查看Object 对象信息

查看JS Object对象信息 //假设_obj 是要查看的对象 var property = ""; for (var item in _obj ) { property += "属性:" + item + "数值:" + _obj [item] + "\n"; } console.log(property) 今天碰到的问题,顺便记录一下 转载自:https...

longtime的博客 1519

Labwindows CVI写上位机与STM32下位机通信(二)

接着上篇,这篇主要谈谈流量计数据读取。我们使用的MEMS流量计采用Modbus协议Modbus 使用RS-485 作为硬件载体。 一. Modbus协议   该协议定义了 Modbus 总线Master(主设备)与Slave(从设备)之间的通讯报文格式,对于主设备来说,Modbus 协议是联系上位机(如PC、PLC、HMI 等)的接口,而且所有的通讯都是“透明的”。控制器通信使用主-从技术,即

yang2011079080010的专栏 1万+

this:[object Object](查看this对象)

console.log("this:" + JSON.stringify(this));

小丁的博客 360

零基础速成simulink代码生成——stateflow基础3

此专栏面向嵌入式工程没有matlab开发经验的人,可以快速学习和实践这门技术。MDB技术,越来越成熟和普遍,从手写代码转到基于模型开发已经是大势,不仅减少开发周期,还增加代码的复用性。汽车领域、医疗和算法建模广泛使用。

不断debug,优化中…… 1711

AI训练师三级考证避坑指南|假证辨别+机构套路+OSTA验证

这是最基础的问题,也是最容易忽略的问题。人工智能训练师三级证书本身是有价值的——政府认可的职业技能等级证书、多地紧缺工种补贴、人才引进加分。但正因为有价值,才引来了大量骗子。记住三句话OSTA查不到的证,一分钱都不值声称免考包过的,100%是骗子培训费一次性谈清楚,后续加价直接走人如果你正在考虑考人工智能训练师三级证书,想要从报名到备考到拿证的完整一站式指南,欢迎查看我的付费专栏:📖《人工智能训练师三级·从零到拿证完全指南》99篇系统化内容,覆盖报名、备考、冲刺、拿证全流程。

白话机器学习 1218

Java——Object 类详解

我们现在有一个 Person 类,类中有名字和年龄属性,我们给 Person 类重写一个 equals 方法,要求如果名字和年龄两个属性相同就可以返回 true,否则返回 false。return age;

Stewie Lee的博客 5181

添加USB wifi驱动到RK3568

在日常开发中我们经常需要用到wifi功能,一般来说soc厂家都会事先做好了几个厂家的wifi驱动在内核源码目录下,我们只需要按原理图配置对应的设备树即可。常用的wifi的接口有:USBSDIOPCIE下面来介绍这这种接口是如何使用wifi芯片。提示:以下是本篇文章正文内容,下面案例可供参考本小节介绍了一个配置一个USBwifi驱动的整个流程,并没有介绍到SDIO,下小节基于AP6256介绍如何使用。

qq_24093081的博客 2049

Java 8中 Objects 类源码实现与分析

Objects 类位于 java.util 包下,自 JDK 1.7 版本新增的,它是一个 final 类,不能被继承,且构造函数是 private 的,不能被实例化,它提供了一系列操作Object对象的静态方法,通常会被当做工具类去使用...

guanshengg的博客 560

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

深度剖析JDK 8中Object:源码级解读与实战探秘

摘要 JDK 8中的Object类是Java所有类的根父类,为所有对象提供基础方法和统一规范。本文从源码层面深入解析Object类,重点剖析其核心方法:getClass()返回对象运行时类;hashCode()提供哈希码用于哈希表;equals()默认实现对象地址比较;clone()实现浅拷贝,需配合Cloneable接口使用。文章还探讨了静态初始化块、native方法注册机制,以及方法重写的规范要求。通过源码分析揭示Object类的设计思想,为理解Java对象基础行为和实现自定义类提供理论依据。

csdn_tom_168的博客 799

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

java源码阅读之java.util.Objects

之所以写这篇文章,是因为工作中接触到一个开源项目代码,而这个开源代码使用到了这个类。同时如果不是前面的包名java.util,都很容易看错成java超类java.lang.Object。 java.util.Objects是java1.7新增的一个类。下面这篇文章将基于1.7.0_80版本的类库源码展开。 一、类定义: package java.util; /** * @since 1...

guohengcook的博客 1018

【从入门到起飞】JavaAPI—System,Runtime,Object,Objects类

JavaAPI—System,Runtime,Object,Objects类

小吉妙妙屋 5281

Java的常用类库——java.util.Objects

java.util.ObjectsObjects 与 Object 区别Objects 方法介绍与分析1. equals2、deepEquals Objects 与 Object 区别 Object 是 Java 中所有类的基类,位于java.lang包。所有对象(包括数组)都实现此类的方法。 Objects 是 Object 的工具类,位于java.util包。它从jdk1.7开始才出现,被final修饰不能被继承,拥有私有的构造函数。 此类包含static实用程序方法,用于操作对象或在操作前检查某些条件

weixin_46312449的博客 2396

Objects类源码分析

1.这个类的基本说明: 从这段代码,可以看出,这个类包括了非空检查、方法的非空参数检查、 比较对象的hashCode、为对象返回一个字符串表示、比较两个对象。 2.构造方法 1、这个类从jdk1.7开始出现的; 2、该类是使用final修饰的,不能被继承; 3、该类的构...

chuangyu5704的博客 234

【Java】java.util.Objects 源码学习

2017-02-10 by 安静的下雪天  http://www.cnblogs.com/quiet-snowy-day/p/6387321.html      本篇概要 Objects 与 Object 区别 Objects 各方法介绍与分析     equals    deepEquals   hashCode   hash     toString   compare   re

t91zzh5f的专栏 277

java objects知道_java.util.Objects分析讲解与调试

今天在研究HashMap在1.8中的源码改动时,随手F3了链表节点Node类的equals方法里的equals 忽然发现,咦,好奇怪,怎么工程里打开了两个Object, 仔细一看才发现一个是Object,一个是Objects,差一个s。所在的包也不一样,一个是java.lang.Object,一个是java.util.Objects。再一看这个Objects类在1.7就已经加入了,有点汗颜,作为一...

weixin_34746715的博客 266

java1.8中Object类源码分析

文章目录1.Object对象的源码1.1 registerNatives1.2 getClass1.3 hashCode1.4 equals1.5 clone1.6 toString1.7 notify1.8 notifyAll1.9 wait(long timeout, int nanos)1.10 wait(long timeout)1.11 wait()1.12 finalize() 1.Object对象的源码 Object类是一切类的超类,在类继承的树形结构上,Object是所有类的根节点。所有的对

dhaibo1986的专栏 2433

JDK 自带Objects类 方法解析

Objects 对于Object 的关系类似于Collections 对于Collect,十分有意思 ---------------------------------------------------------------------------------------------- 更新:辛苦码了这么多字,结果发现一篇更好的博客,出于良心,文章就成转载的了 1.Objects 的e...

weixin_42327945的博客 473
上一篇: Java动态编程之Instrumentation
下一篇: Java中的封装的实现,访问限定符、包
Java_ttcd
博客等级 码龄4年 198粉丝 190原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值