官方文档定义
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.
该类位于java.lang(java语言核心包)包下。这个类有一个无参的构造方法以及若干个常用方法protected Object clone()、boolean equals()、protected void finalize()、Class<?>getClass()、int hashCode()、void notify()、void notifyAll()、String toString()、void wait()、void wait(long timeout)、void wait(long timeout,int nanos)
因为每个类都继承自该类,所以所有的类都具有这些方法。
方法详解
public String 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())
Object类的toString方法返回一个字符串,这个字符串由实例对象的名称+@+该对象的无符号的十六进制哈希码
注意:java语言的8种基本数据类型没有toString()方法,但是他们的包装类具有该方法,而且Object的子类都重写了该方法
public int hashCode()
HashMap
.public boolean equals(Object obj)
protected Object clone()throws CloneNotSupportedException
请参照详解Java中的clone方法 -- 原型模式
protected void finalize()throws Throwable
其余的几个是和线程相关的方法