等牛奶的咖啡

经营属于我们的咖啡屋

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  0 随笔 :: 8 文章 :: 0 评论 :: 0 Trackbacks
  1 /**
  2  * 提供程序设计的基础类
  3  */
  4 package java.lang;
  5 
  6 /**
  7  * 类层次结构的根类
  8  */
  9 public class Object {
 10 
 11     /**
 12      * 注册一些本地方法,具体实现在DLL中
 13      */
 14     private static native void registerNatives();
 15 
 16     static {
 17         registerNatives();
 18     }
 19 
 20     /**
 21      * 返回此 Object 的运行时类
 22      * 不可以被重写
 23      */
 24     public final native Class<?> getClass();
 25 
 26     /**
 27      * 返回对象的哈希码值
 28      */
 29     public native int hashCode();
 30 
 31     /**
 32      * 指示其他某个对象是否与此对象相等,比较的是对象的引用
 33      * 有些子类会重写该方法,以使其具有比较对象内容的功能
 34      * 子类在重写该方法的时候,通常要重写 hashCode() 方法
 35      */
 36     public boolean equals(Object obj) {
 37         return (this == obj);
 38     }
 39 
 40     /**
 41      * 创建并返回此对象的一个副本
 42      * 这个方法被定义为 protected ,调用此方法需要实现 Cloneable 接口
 43      * 否则抛出异常 CloneNotSupportedException
 44      */
 45     protected native Object clone() throws CloneNotSupportedException;
 46 
 47     /**
 48      * 返回该对象的字符串表示,类名@对象哈希码的无符号十六进制
 49      */
 50     public String toString() {
 51         return getClass().getName() + "@" + Integer.toHexString(hashCode());
 52     }
 53 
 54     /**
 55      * 唤醒在此对象监视器上等待的单个线程
 56      * 不可以被重写
 57      */
 58     public final native void notify();
 59 
 60     /**
 61      * 唤醒在此对象监视器上等待的所有线程
 62      * 不可以被重写
 63      */
 64     public final native void notifyAll();
 65 
 66     /**
 67      * 在其他线程调用此对象的 notify()方法或notifyAll() 方法,或者超过指定的时间量前,导致当前线程等待
 68      * 不可以被重写
 69      */
 70     public final native void wait(long timeout) throws InterruptedException;
 71 
 72     /**
 73      * 在其他线程调用此对象的 notify() 方法或 notifyAll()
 74      * 方法,或者其他某个线程中断当前线程,或者已超过某个实际时间量前,导致当前线程等待
 75      * 不可以被重写
 76      */
 77     public final void wait(long timeout, int nanos) throws InterruptedException {
 78         if (timeout < 0) {
 79             throw new IllegalArgumentException("timeout value is negative");
 80         }
 81 
 82         if (nanos < 0 || nanos > 999999) {
 83             throw new IllegalArgumentException(
 84                     "nanosecond timeout value out of range");
 85         }
 86 
 87         if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 88             timeout++;
 89         }
 90 
 91         wait(timeout);
 92     }
 93 
 94     /**
 95      * 在其他线程调用此对象的 notify() 方法或 notifyAll() 方法前,导致当前线程等待
 96      * 不可以被重写
 97      */
 98     public final void wait() throws InterruptedException {
 99         wait(0);
100     }
101 
102     /**
103      * 对象的垃圾回收器调用此方法,具体实现的方法体由子类重写此方法
104      */
105     protected void finalize() throws Throwable {
106     }
107 }
108 
posted on 2009-10-27 21:50 等牛奶的咖啡 阅读(248) 评论(0)  编辑  收藏 所属分类: JDK源代码

只有注册用户登录后才能发表评论。


网站导航: