java object默認的基本方法中沒有copy(),含有以下方法:
getClass(), hashCode(), equals(), clone(), toString(), notify(), notifyAll(), wait(), finalize()java
拿出來源碼對比一下方法:程序員
- package java.lang;
- public class Object {
-
- /* 一個本地方法,具體是用C(C++)在DLL中實現的,而後經過JNI調用。*/
- private static native void registerNatives();
- /* 對象初始化時自動調用此方法*/
- static {
- registerNatives();
- }
- /* 返回此 Object 的運行時類。*/
- public final native Class<?> getClass();
-
- /*
- hashCode 的常規協定是:(本質 上是 返回該對象的哈希碼值。 )
-
- 1.在 Java 應用程序執行期間,在對同一對象屢次調用 hashCode 方法時,必須一致地返回相同的整數,前提是將對象進行 equals 比較時所用的信息沒有被修改。從某一應用程序的一次執行到同一應用程序的另外一次執行,該整數無需保持一致。
- 2.若是根據 equals(Object) 方法,兩個對象是相等的,那麼對這兩個對象中的每一個對象調用 hashCode 方法都必須生成相同的整數結果。
- 3.若是根據 equals(java.lang.Object) 方法,兩個對象不相等,那麼對這兩個對象中的任一對象上調用 hashCode 方法不 要求必定生成不一樣的整數結果。可是,程序員應該意識到,爲不相等的對象生成不一樣整數結果能夠提升哈希表的性能。
- */
-
- public native int hashCode();
-
-
- public boolean equals(Object obj) {
- return ( this == obj);
- }
-
- /*本地CLONE方法,用於對象的複製。*/
- 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() 方法前,致使當前線程等待。換句話說,此方法的行爲就好像它僅執行 wait(0) 調用同樣。
- 當前線程必須擁有此對象監視器。該線程發佈對此監視器的全部權並等待,直到其餘線程經過調用 notify 方法,或 notifyAll 方法通知在此對象的監視器上等待的線程醒來。而後該線程將等到從新得到對監視器的全部權後才能繼續執行。*/
- public final void wait() throws InterruptedException {
- wait( 0 );
- }
-
-
-
- /*在其餘線程調用此對象的 notify() 方法或 notifyAll() 方法,或者超過指定的時間量前,致使當前線程等待。*/
- public final native void wait( long timeout) throws InterruptedException;
-
- /* 在其餘線程調用此對象的 notify() 方法或 notifyAll() 方法,或者其餘某個線程中斷當前線程,或者已超過某個實際時間量前,致使當前線程等待。*/
- 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);
- }
-
- /*當垃圾回收器肯定不存在對該對象的更多引用時,由對象的垃圾回收器調用此方法。*/
- protected void finalize() throws Throwable { }
- }