每個類別都會extends Object ,所以程式不要寫,就會自動extends。
所有物件(包括陣列)都實作這個類別的方法。
用法:
只有一個建構子(constructor) Object()。
Object object =new Object();
常用的方法:
boolean | equals(Object obj)指示其他某個物件是否與此物件「相等」。 |
Object object =new Object();
Object object1 =new Object();
System.out.println(object.equals(object1));//false
Object object2 = object;
System.out.println(object.equals(object2));//true
String | toString()返回該物件的字元串表示。 |
Object 類別的 toString 方法返回一個字元串,
該字元串由類別名(物件是該類別的一個實例)、
at 標記符“@”和此物件雜湊碼的無符號十六進製表示組成。
換句話說,該方法返回一個字元串,它的值等於:
getClass().getName() + '@' + Integer.toHexString(hashCode())
System.out.println(object.toString());//java.lang.Object@ecd7e
System.out.println(object1.toString());//java.lang.Object@1d520c4
System.out.println(object2.toString());//java.lang.Object@ecd7e
其它方法:
protected Object | clone()創建並返回此物件的一個副本。 |
protected void | finalize()當垃圾回收器確定不存在對該物件的更多參考時,由物件的垃圾回收器調用此方法。 |
Class<?> | getClass()返回此 Object 的運行時類別。 |
int | hashCode()返回該物件的雜湊碼值。 |
void | notify()喚醒在此物件監視器上等待的單個執行緒。 |
void | notifyAll()喚醒在此物件監視器上等待的所有執行緒。 |
void | wait()在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法前,導致當前執行緒等待。 |
void | wait(long timeout)在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法,或者超過指定的時間量前,導致當前執行緒等待。 |
void | wait(long timeout, int nanos)在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法,或者其他某個執行緒中斷當前執行緒,或者已超過某個實際時間量前,導致當前執行緒等待。 |
notify、notifyAll、wait
另章介紹
建製中…
回收器相關的方法:
finalize()
另章介紹
建製中…
取得class 套件名稱:
System.out.println(object.getClass());//class java.lang.Object
複製的方法:
clone()
另章介紹
[JAVA]Object-物件的複製使用clone()
JAVA Object API
Object (Java Platform SE 6)
其它文章
沒有留言:
張貼留言