类Object

Object 是类层次结构的根类。每个类都使用 Object 作为超类。所有对象(包括数组)都实现这个类的方法。
protected  Objectclone()
          创建并返回此对象的一个副本。
 booleanequals(Object obj)
          指示其他某个对象是否与此对象“相等”。
protected  voidfinalize()
          当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法。
 Class<?>getClass()
          返回此 Object 的运行时类。
 inthashCode()
          返回该对象的哈希码值。
 voidnotify()
          唤醒在此对象监视器上等待的单个线程。
 voidnotifyAll()
          唤醒在此对象监视器上等待的所有线程。
 StringtoString()
          返回该对象的字符串表示。
 voidwait()
          在其他线程调用此对象的 notify() 方法或 notifyAll() 方法前,导致当前线程等待。
 voidwait(long timeout)
          在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者超过指定的时间量前,导致当前线程等待。
 voidwait(long timeout, int nanos)
          在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者其他某个线程中断当前线程,或者已超过某个实际时间量前,导致当前线程等待。
类Object源码分析:
package java.lang;

public class Object {
	//调用本地方法
    private static native void registerNatives();
    static {
        registerNatives();
    }
	//返回此Object的运行时类
    public final native Class<?> getClass();
	//返回对象的哈希值
    public native int hashCode();
	//判断两个对象相等
    public boolean equals(Object obj) {
	return (this == obj);
    }
    protected native Object clone() throws CloneNotSupportedException;
	//返回对象的字符串表示
    public String toString() {
	return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
	//唤醒线程
    public final native void notify();
    public final native void notifyAll();
	//在其他线程调用此对象的 notify() 方法或 notifyAll() 方法前,导致当前线程等待。
    public final native void wait(long timeout) throws InterruptedException;

  
    public final void wait(long timeout, int nanos) throws InterruptedException {
        if (timeout < 0) {
            throw new IllegalArgumentException("timeout value is negative");
        }

        if (nanos < 0 || nanos > 999999) {
            throw new IllegalArgumentException(
				"nanosecond timeout value out of range");
        }

	if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
	    timeout++;
	}

	wait(timeout);
    }


    public final void wait() throws InterruptedException {
	wait(0);
    }
	//当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法。
    protected void finalize() throws Throwable { }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值