• What methods does the Object class have?
  • I’m here today to comb and record.

What are they?

Let me elaborate

It can be seen that the basic methods are native, you have to see the IMPLEMENTATION of the JVM to know the specific logic. I’m not going to do that here.

// To register the local method, you can use Baidu private static native void registerNatives(); static { registerNatives(); }Copy the code
Public final native class <? > getClass();Copy the code
Public native int hashCode();Copy the code
Public Boolean equals(Object obj) {return (this == obj); }Copy the code
/ / Object clone protected native Object clone () throws CloneNotSupportedException;Copy the code
Public String toString() {return getClass().getName() + "@" + Integer.toHexString(hashCode()); }Copy the code
Public final native void notify();Copy the code
Public final native void notifyAll();Copy the code
/** Object Wait (long timeout) lets the current thread wait(block) until another thread calls notify() or notifyAll() of the Object, or the timeout time is exceeded. If the timeout parameter is 0, it will not timeout and will wait forever, similar to the wait() method. The current thread must be the object of the monitor owner, otherwise or IllegalMonitorStateException abnormal happens. If the current thread is interrupted by any thread before or while waiting, InterruptedException is thrown. If the argument passed is invalid, an IllegalArgumentException is thrown. **/ public final native void wait(long timeout) throws InterruptedException;Copy the code
/** Object wait(long timeout, int nanos) lets the current thread wait(block) until another thread calls notify() or notifyAll() of the Object. Or exceed the timeout specified by timeout and Nanos. This method is similar to the wait(long timeout) method, with the addition of a nanos parameter that represents the extra time (in nanoseconds ranging from 0 to 999999). So we have to add nanos nanoseconds to the timeout. If both the timeout and nanos parameters are 0, the timeout will not timeout and the wait will continue, similar to the wait() method. The current thread must be the object of the monitor owner, otherwise or IllegalMonitorStateException abnormal happens. If the current thread is interrupted by any thread before or while waiting, InterruptedException is thrown. If the argument passed is invalid or nanos is not in the 0-999999 range, IllegalArgumentException 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); }Copy the code
/** Object wait() makes the current thread wait. Until another thread calls notify() or notifyAll() on the object. The current thread must be the object of the monitor owner, otherwise or IllegalMonitorStateException abnormal happens. If the current thread is interrupted by any thread before or while waiting, InterruptedException is thrown. **/ public final void wait() throws InterruptedException { wait(0); }Copy the code
The /** Object Finalize () method is used to trigger the action when the instance is collected by the garbage collector. The object's garbage collector calls this method when the GC (garbage collector) determines that there are no more references to the object. * * * * * * * * * * * * it's best not to rewrite this method * * * * * * * * * * * * * * * / protected void finalize () throws Throwable {}Copy the code

How many bytes does new Object() take?