在java.lang包下
Object類:是全部類的基類(父類)
public final native Class<?> getClass();
返回這個Object所表明的的運行時類
public native int hashCode();//返回對象hash code 值
若是是兩個相同(指用=比較都爲true的)的對象調用這個方法,會返回相同的Integer類型的hash碼;
若是是兩個不相同(指用=比較都爲false的)的對象調用這個方法,會返回不一樣的Integer類型的hash碼;
/**
* The {@code equals} method for class {@code Object} implements
* the most discriminating possible equivalence relation on objects;
* that is, for any non-null reference values {@code x} and
* {@code y}, this method returns {@code true} if and only
* if {@code x} and {@code y} refer to the same object
* ({@code x == y} has the value {@code true}).
* <p>
*/
public boolean equals(Object obj) {
return (this == obj);
}
返回值表示兩個對象是否"相同".true表示"相同",false表示"不相同"。
x.equals(x) 返回true。
非空引用x,y:
若是x.equals(y) 返回true,那麼y.equals(x) 也返回true。
具備傳遞性:
非空引用x,y,z:
若是 x.equals(y) 返回true, y.equals(z) 返回true,那麼x.equals(z) 也返回true
若是x非空:
x.equals(null) 返回false。
參數obj表明要與之比較的對象,也就是要被比較de對象。
當equals方法被重寫的時候,必須也要重寫hashCode方法,確保擁有相同的hash碼。
protected native Object clone() throws CloneNotSupportedException;
返回一個複製的對象(注意淺複製、深複製)。
調用這個方法的對象所在的類須要實現Cloneable接口才能使用到此方法,不然會拋出CloneNotSupportedException異常。
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;
timeout的單位爲 毫秒。
讓線程進入等待,直到另外一個線程調用notify()或notifyAll()方法或者超過了設置的時間timeout 纔會中止等待。
當前線程必須擁有對象的監視器(鎖)。
若是當前線程在等待以前或等待期間被任何線程中斷,則會拋出InterruptedException異常。
若是當前線程不是對象監視器所擁有的,則拋出IllegalMonitorStateException異常。
若是timeout是負數,則拋出IllegalArgumentException異常。
/*@param timeout the maximum time to wait in milliseconds.
* @param nanos additional time, in nanoseconds range
* 0-999999.
* @throws IllegalArgumentException if the value of timeout is
* negative or the value of nanos is
* not in the range 0-999999.
* @throws IllegalMonitorStateException if the current thread is not
* the owner of this object's monitor.
* @throws InterruptedException if any thread interrupted the
* current thread before or while the current thread
* was waiting for a notification. The <i>interrupted
* status</i> of the current thread is cleared when
* this exception is thrown.
*/
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 > 0) {
timeout++;
}
wait(timeout);
}
nanos:額外的時間,以納秒爲單位,範圍在0-999999.
讓線程進入等待,直到另外一個線程調用notify()或notifyAll()方法或者超過了設置的時間timeout 纔會中止等待。
timeout的單位爲 毫秒。
讓線程進入等待,直到另外一個線程調用notify()或notifyAll()方法或者超過了設置的時間timeout 纔會中止等待。
當前線程必須擁有對象的監視器(鎖)。
若是當前線程在等待以前或等待期間被任何線程中斷,則會拋出InterruptedException異常。
若是當前線程不是對象監視器所擁有的,則拋出IllegalMonitorStateException異常。
若是timeout是負數,則拋出IllegalArgumentException異常。
若是nanos範圍越界,則拋出IllegalArgumentException異常。
public final void wait() throws InterruptedException {
wait(0);
}
這個方法就像在調用wait(0);
讓線程進入等待,直到另外一個線程調用notify()或notifyAll()方法或者超過了設置的時間timeout 纔會中止等待。
讓線程進入等待,直到另外一個線程調用notify()或notifyAll()方法或者超過了設置的時間timeout 纔會中止等待。
當前線程必須擁有對象的監視器(鎖)。
若是當前線程在等待以前或等待期間被任何線程中斷,則會拋出InterruptedException異常。
若是當前線程不是對象監視器所擁有的,則拋出IllegalMonitorStateException異常。
protected void finalize() throws Throwable { }
當肯定再也不有對該對象的引用時,垃圾回收時由對象上的垃圾回收器調用