栏目:Java8基础 作者:admin 日期:2014-12-19 评论:1 点击: 1,698 次
本文标签: object
java 作为一门纯粹的面向对象语言,它的最根源来源于object类,今天我就分析一下这个类的源码,如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
public class Object { private static native void registerNatives(); static { registerNatives(); } //获得class对象 public final native Class<?> getClass(); //获得hashCode public native int hashCode(); //是否相等 public boolean equals(Object obj) { return (this == obj); } //克隆 protected native Object clone() throws CloneNotSupportedException; //显示名称:类名@hashCode的十六进制表示 public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); } //随机唤醒等待队列上的任意一个线程 public final native void notify(); //唤醒等待队列上的所有线程 public final native void 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 { } } |
------====== 本站公告 ======------
金丝燕网,一个严谨的网站!