I. Introduction
The Java Object class is the parent class of all classes, that is, all classes in Java inherit Object, and subclasses can use all methods of Object. The Object class is located in the java.lang package and is automatically imported at compile time. When we create a class, if we do not explicitly inherit a parent class, it will automatically inherit Object and become a subclass of Object.
2. Detailed explanation of Object method
By reading the source code, we can see that Object contains: Object(), getClass(), hashCode(), equals(), clone(), toString(), notify(), notifyAll(), wait(long), wait(long,int ), wait(), finalize() a total of twelve methods.
A brief description of the functions of these methods:
1. Object(): Default Constructor
public Object() {
throw new RuntimeException("Stub!");
}
复制代码
2. clone(): Create and return a copy of this object
@RecentlyNonNull
protected Object clone() throws CloneNotSupportedException {
throw new RuntimeException("Stub!");
}
复制代码
3. equals(): Indicates whether some other object is equal to this object
public boolean equals(@Nullable Object obj) {
throw new RuntimeException("Stub!");
}
复制代码
4. finalize(): This method is called by the garbage collector of an object when the garbage collector determines that there are no more references to the object
protected void finalize() throws Throwable {
throw new RuntimeException("Stub!");
}
复制代码
5. getClass(): Returns the runtime class of an object
@NonNull
public final Class<?> getClass() {
throw new RuntimeException("Stub!");
}
复制代码
6. hashCode(): Returns the hash value of the object
public int hashCode() {
throw new RuntimeException("Stub!");
}
复制代码
7. notify(): wake up a single thread waiting on this object monitor
public final native void notify();
复制代码
8. notifyAll(): wake up all threads waiting on this object monitor
public final native void notifyAll();
复制代码
9. toString(): Returns the string representation of the object
@NonNull
public String toString() {
throw new RuntimeException("Stub!");
}
复制代码
10. wait(): Causes the current thread to wait until other threads call notify() or notifyAll() of this object
public final void wait() throws InterruptedException {
throw new RuntimeException("Stub!");
}
复制代码
11. wait(long timeout): Causes the current thread to wait to call notify() or notifyAll() of this object
public final void wait(long timeout) throws InterruptedException {
throw new RuntimeException("Stub!");
}
复制代码
12. wait(long timeout, int nanos): Causes the current thread to wait until another thread calls notify() or notifyAll() of this object, or some other thread interrupts the current thread, or some actual amount of time has passed
public final native void wait(long var1, int var3) throws InterruptedException;
复制代码