1. 程式人生 > 實用技巧 >Java Object 類常用方法總結

Java Object 類常用方法總結

總結

public final native Class<?> getClass()    //返回此 Object 執行時的類
 
public native int hashCode()    //返回物件的雜湊碼
 
public boolean equals(Object obj)    //判斷其他物件與此物件是否“相等”
 
protected native Object clone() throws CloneNotSupportedException    //建立並返回此物件的一個副本
 
public String toString()    //返回物件的字串表示
 
public final native void notify()    //喚醒在此物件監視器上等待的單個執行緒
 
public final native void notifyAll()    //喚醒在此物件監視器上等待的所有執行緒
 
public final native void wait(long timeout) throws InterruptedException    //使當前物件的執行緒等待 timeout 時長
 
public final void wait(long timeout, int nanos) throws InterruptedException    //使當前物件的執行緒等待 timeout 時長,或其他執行緒中斷當前執行緒
 
public final void wait() throws InterruptedException    //使當前物件的執行緒等待 
 
protected void finalize() throws Throwable {}    //垃圾回收時呼叫該方法