1 /**
2 * 提供程序設(shè)計的基礎(chǔ)類
3 */
4 package java.lang;
5
6 /**
7 * 類層次結(jié)構(gòu)的根類
8 */
9 public class Object {
10
11 /**
12 * 注冊一些本地方法,具體實現(xiàn)在DLL中
13 */
14 private static native void registerNatives();
15
16 static {
17 registerNatives();
18 }
19
20 /**
21 * 返回此 Object 的運(yùn)行時類
22 * 不可以被重寫
23 */
24 public final native Class<?> getClass();
25
26 /**
27 * 返回對象的哈希碼值
28 */
29 public native int hashCode();
30
31 /**
32 * 指示其他某個對象是否與此對象相等,比較的是對象的引用
33 * 有些子類會重寫該方法,以使其具有比較對象內(nèi)容的功能
34 * 子類在重寫該方法的時候,通常要重寫 hashCode() 方法
35 */
36 public boolean equals(Object obj) {
37 return (this == obj);
38 }
39
40 /**
41 * 創(chuàng)建并返回此對象的一個副本
42 * 這個方法被定義為 protected ,調(diào)用此方法需要實現(xiàn) Cloneable 接口
43 * 否則拋出異常 CloneNotSupportedException
44 */
45 protected native Object clone() throws CloneNotSupportedException;
46
47 /**
48 * 返回該對象的字符串表示,類名@對象哈希碼的無符號十六進(jìn)制
49 */
50 public String toString() {
51 return getClass().getName() + "@" + Integer.toHexString(hashCode());
52 }
53
54 /**
55 * 喚醒在此對象監(jiān)視器上等待的單個線程
56 * 不可以被重寫
57 */
58 public final native void notify();
59
60 /**
61 * 喚醒在此對象監(jiān)視器上等待的所有線程
62 * 不可以被重寫
63 */
64 public final native void notifyAll();
65
66 /**
67 * 在其他線程調(diào)用此對象的 notify()方法或notifyAll() 方法,或者超過指定的時間量前,導(dǎo)致當(dāng)前線程等待
68 * 不可以被重寫
69 */
70 public final native void wait(long timeout) throws InterruptedException;
71
72 /**
73 * 在其他線程調(diào)用此對象的 notify() 方法或 notifyAll()
74 * 方法,或者其他某個線程中斷當(dāng)前線程,或者已超過某個實際時間量前,導(dǎo)致當(dāng)前線程等待
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 * 在其他線程調(diào)用此對象的 notify() 方法或 notifyAll() 方法前,導(dǎo)致當(dāng)前線程等待
96 * 不可以被重寫
97 */
98 public final void wait() throws InterruptedException {
99 wait(0);
100 }
101
102 /**
103 * 對象的垃圾回收器調(diào)用此方法,具體實現(xiàn)的方法體由子類重寫此方法
104 */
105 protected void finalize() throws Throwable {
106 }
107 }
108
2 * 提供程序設(shè)計的基礎(chǔ)類
3 */
4 package java.lang;
5
6 /**
7 * 類層次結(jié)構(gòu)的根類
8 */
9 public class Object {
10
11 /**
12 * 注冊一些本地方法,具體實現(xiàn)在DLL中
13 */
14 private static native void registerNatives();
15
16 static {
17 registerNatives();
18 }
19
20 /**
21 * 返回此 Object 的運(yùn)行時類
22 * 不可以被重寫
23 */
24 public final native Class<?> getClass();
25
26 /**
27 * 返回對象的哈希碼值
28 */
29 public native int hashCode();
30
31 /**
32 * 指示其他某個對象是否與此對象相等,比較的是對象的引用
33 * 有些子類會重寫該方法,以使其具有比較對象內(nèi)容的功能
34 * 子類在重寫該方法的時候,通常要重寫 hashCode() 方法
35 */
36 public boolean equals(Object obj) {
37 return (this == obj);
38 }
39
40 /**
41 * 創(chuàng)建并返回此對象的一個副本
42 * 這個方法被定義為 protected ,調(diào)用此方法需要實現(xiàn) Cloneable 接口
43 * 否則拋出異常 CloneNotSupportedException
44 */
45 protected native Object clone() throws CloneNotSupportedException;
46
47 /**
48 * 返回該對象的字符串表示,類名@對象哈希碼的無符號十六進(jìn)制
49 */
50 public String toString() {
51 return getClass().getName() + "@" + Integer.toHexString(hashCode());
52 }
53
54 /**
55 * 喚醒在此對象監(jiān)視器上等待的單個線程
56 * 不可以被重寫
57 */
58 public final native void notify();
59
60 /**
61 * 喚醒在此對象監(jiān)視器上等待的所有線程
62 * 不可以被重寫
63 */
64 public final native void notifyAll();
65
66 /**
67 * 在其他線程調(diào)用此對象的 notify()方法或notifyAll() 方法,或者超過指定的時間量前,導(dǎo)致當(dāng)前線程等待
68 * 不可以被重寫
69 */
70 public final native void wait(long timeout) throws InterruptedException;
71
72 /**
73 * 在其他線程調(diào)用此對象的 notify() 方法或 notifyAll()
74 * 方法,或者其他某個線程中斷當(dāng)前線程,或者已超過某個實際時間量前,導(dǎo)致當(dāng)前線程等待
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 * 在其他線程調(diào)用此對象的 notify() 方法或 notifyAll() 方法前,導(dǎo)致當(dāng)前線程等待
96 * 不可以被重寫
97 */
98 public final void wait() throws InterruptedException {
99 wait(0);
100 }
101
102 /**
103 * 對象的垃圾回收器調(diào)用此方法,具體實現(xiàn)的方法體由子類重寫此方法
104 */
105 protected void finalize() throws Throwable {
106 }
107 }
108