Object有哪些公用方法

public class 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.

Object是java语言中所有其他类的根类(父类的父类的父类...)

它的所有方法如下:

protected Object clone()
//Creates and returns a copy of this object.
boolean equals(Object obj)
//Indicates whether some other object is "equal to" this one.
protected void finalize()
//Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Class<?> getClass()
//Returns the runtime class of this Object.
int hashCode()
//Returns a hash code value for the object.
void notify()
//Wakes up a single thread that is waiting on this object‘s monitor.
void notifyAll()
//Wakes up all threads that are waiting on this object‘s monitor.
String toString()
//Returns a string representation of the object.
void wait()
//Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
void wait(long timeout)
//Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
//void wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

参考:http://docs.oracle.com/javase/8/docs/api/

时间: 2024-12-30 03:42:40

Object有哪些公用方法的相关文章

Object有哪些公用方法?(转)

Object是所有类的父类,任何类都默认继承Object.Object类到底实现了哪些方法? 1.clone方法 保护方法,实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出CloneNotSupportedException异常. 2.getClass方法 final方法,获得运行时类型. 3.toString方法 该方法用得比较多,一般子类都有覆盖. 4.finalize方法 该方法用于释放资源.因为无法确定该方法什么时候被调用,很少使用. 5.equals方法 该

Object有哪些公用方法?

protected Object clone() 创建并返回此对象的一个副本.public boolean equals(Object obj) 指示其他某个对象是否与此对象"相等".protected void finalize() 当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法.public final Class<?> getClass() 返回此 Object 的运行时类.public int hashCode() 返回该对象的哈希码值.p

Object类有哪些公用方法?

Object是所有类的父类,任何类都默认继承Object. clone 保护方法,实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出CloneNotSupportedException异常 equals 在Object中与==是一样的,子类一般需要重写该方法 hashCode 该方法用于哈希查找,重写了equals方法一般都要重写hashCode方法.这个方法在一些具有哈希功能的Collection中用到 getClass final方法,获得运行时类型 wait 使当

java Object对象的clone方法

参考copy链接:http://blog.csdn.net/bigconvience/article/details/25025561 在看原型模式,发现要用到clone这个方法,以前和朋友聊过,没怎么看过,刚好要用,就看看了. 源码解释: /** * Creates and returns a copy of this object. The precise meaning * of "copy" may depend on the class of the object. The

Object.prototype.toString.call()方法浅谈

参考链接:http://www.cnblogs.com/wyaocn/p/5796142.html 使用Object.prototype上的原生toString()方法判断数据类型,使用方法如下: Object.prototype.toString.call(value) 1.判断基本类型: Object.prototype.toString.call(null);//"[object Null]" Object.prototype.toString.call(undefined);/

Java中Object类的公有方法

HashCode();wait();notify();equals();getClass();toString();clone();finalize(); 这里只是简单介绍一下其中的几个函数: HashCode(): * As much as is reasonably practical, the hashCode method defined by * class {@code Object} does return distinct integers for distinct * obje

Delphi(procedure&amp;procedure .... of object )函数指针与方法指针 .

Delphi(procedure&procedure .... of object )函数指针与方法指针 . delphiobjectbuttonintegerdelphi中经常见到以下两种定义 Type TMouseProc = procedure (X,Y:integer); TMouseEvent = procedure (X,Y:integer) of Object; 两者样子差不多但实际意义却不一样, TMouseProc只是单一的函数指针类型; TMouseEvent是对象的函数指针

Object.prototype.toString.call()方法

使用Object.prototype上的原生toString()方法判断数据类型,使用方法如下: Object.prototype.toString.call(value) 1.判断基本类型: Object.prototype.toString.call(null);//"[object Null]" Object.prototype.toString.call(undefined);//"[object Undefined]" Object.prototype.t

【转】javascript Object使用Array的方法

原文: http://www.cnblogs.com/idche/archive/2012/03/17/2403894.html Array.prototype.push push向数组尾部添加一项并更新length ,返回数组长度. 如果Object使用push会怎样? 看下面代码, obj好像数组一样工作了.length会自动更新. var push = Array.prototype.push;var obj = {};push.call(obj, "hello"); // 返回