1.1 JDK源码阅读之Object

Object类是所有类的父类 

方法解析:

 

得到Class

public final native Class<?> getClass();

 

得到Object hashCode

public native int hashCode();

 

判断hashCode 决定是否equals

public boolean equals(Object obj) {return (this == obj);}

 

克隆Object,clone方法是native方法,native方法的效率远高于非native方法,因此还是使用clone方法去做对象的拷贝而不是使用new的方法来copy。

protected native Object clone() throws CloneNotSupportedException;

 

得到Object名称以及hashCode

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;

 

导致当前的线程等待,直到其他线程调用此对象的notify( ) 方法或 notifyAll( ) 方法,或者其他线程打断了当前线程,或者指定的时间过完。

public final void wait(long timeout, int nanos) throws InterruptedException {}

 

译:导致当前的线程等待,直到其他线程调用此对象的notify( ) 方法或 notifyAll( ) 方法

public final void wait() throws InterruptedException { wait(0); }

 

通知jvm  进行gc()

protected void finalize() throws Throwable { }

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值