java源码——java.lang.Object
来源:互联网 发布:淘宝能微信支付吗 编辑:程序博客网 时间:2024/05/22 06:37
—Object—
Class Object
is the root of the class hierarchy. Every class has Object
as a superclass. All objects, including arrays, implement the methods of this class.——From Oracle
—释义—
Object类是java中所有对象所继承的父类,即便是数组也继承了该父类(可以理解为原始类,所有类的祖先,你也许会想问:詹姆斯第一个写的类是不是Object?)。
所有类对Object类的继承都是隐式继承,所以无法看到。
—Object—
默认构造方法
—clone—
—equals—
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation on non-nullobjectreferences: —From ORacle—
源码:
public boolean equals(Object obj) { return (this == obj); }
通过源码我们看到,原始类equals其实与“==”是等价的。—finalize—
—getClass—
—hashcode—
In the Java programming language, every class implicitly or explicitly provides a hashCode()
method, which digests the data stored in an instance of the class into a single hash value (a 32-bit signed integer). This hash is used by other code when storing or manipulating the instance – the values are intended to be evenly distributed for varied inputs for use in clustering. This property is important to the performance of hash tables and other data structures that store objects in groups ("buckets") based on their computed hash values. Technically, in Java, hashCode() by default is a native method, meaning, it has the modifier 'native', as it is implemented directly in the native code in the JVM.
Source:Wikipedia
java中每个类都隐式或者显式的实现了Object的hashcode方法。
跟谷歌和官方个人总结,作者为什么要在原始类中存在hashcode呢?
①、类对象的存储优化,便于查找类对象。
②、配合equals使用。
注意:很多博客表示hashcode方法返回的是该类的物理存储地址或者是逻辑存储地址,这个说法是错误的,按照官方的说法:返回的32位值只是与类对象的存储位置有关。
—notify—
—notifyall—
—toString—
The toString
method for class Object
returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@
', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
源码: public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); }
返回一个格式为类名+@+该类的hash值。
—wait—
finalize()
- java源码——java.lang.Object
- java.lang.Object源码浅析
- Java源码心中有数系列 java.lang.Object
- java.lang之java.lang.Object源码阅读及分析
- 源码阅读笔记:java.lang.Object
- JDK源码学习--java.lang.Object类
- Java.lang包——Object类
- 黑马程序员——java.lang.Object
- java.lang.Object类
- java.lang.Object类
- java.lang.Object类
- 认识 java.lang.Object
- java.lang.Object.clone()
- java.lang.Object学习
- 01 java.lang.Object
- 浅谈java.lang.object
- Java.lang.Object 类
- java.lang.Object
- 时间序列分析这件小事(八)----格兰杰因果关系检验
- 大数据与网络分析的平台和工具
- ffmpeg之如何获得一个媒体文件的AVStream,并从该基础上获得AVCodec,AVCodecContext
- Android studio中的问题解决方案
- 在Android Studio中进行单元测试和UI测试
- java源码——java.lang.Object
- 面向切面编程的作用与实现简介
- git 命令总结
- 硅钢片之让步品
- ios8之后的UIAlertController详解
- POJ2003 RE到shi ,树存储的数据结构
- jsonp跨域请求资源使用方法与简单原理
- ASPAJAXExtSetup安装及配置
- c语言计算二维数组的行数、列数