Module java.base
Package java.lang

# Class Object

≠
public class Object
Comparing jdk-master and valhalla-csr-open

public class Object
Class `Object` is the root of the class hierarchy. Every class has `Object` as a superclass. All objects, including arrays, implement the methods of this class.
Moved to a division with class preview-block.
When preview features are enabled, subclasses of `java.lang.Object` can be either an identity classPREVIEW or a value classPREVIEW . See The Java Language Specification 8.1.1.5 Value ClassesPREVIEW . Use of value class instances for synchronization, mutexes, or with object references result in `IdentityException` PREVIEW .

Since:
  1.0
See Also:
  - `Class`

## Constructors

- =
  public Object()

## Methods

- =
  protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
- =
  public boolean equals(java.lang.Object arg0)
- =
  @Deprecated(since="9"forRemoval=true)
  protected void finalize() throws java.lang.Throwable
- =
  public final java.lang.Class<?> getClass()
- =
  public int hashCode()
- ≠
  public final void notify()
  Comparing jdk-master and valhalla-csr-open

  ### notify

  public final void notify()
  Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the `wait` methods.

  The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.

  This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

  - By executing a synchronized instance method of that object.
  - By executing the body of a `synchronized` statement that synchronizes on the object.
  - For objects of type `Class,` by executing a static synchronized method of that class.

  Only one thread at a time can own an object's monitor.

  If this object is a value objectPREVIEW , it does does not have a monitor, an `IllegalMonitorStateException` is thrown.
  Throws:
    `IllegalMonitorStateException` - if the current thread is not the owner of this object's monitor or if this object is a value objectPREVIEW .
  See Also:
    - `notifyAll()`
    - `wait()`
- ≠
  public final void notifyAll()
  Comparing jdk-master and valhalla-csr-open

  ### notifyAll

  public final void notifyAll()
  Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the `wait` methods.

  The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.

  This method should only be called by a thread that is the owner of this object's monitor. See the `notify` method for a description of the ways in which a thread can become the owner of a monitor.

  If this object is a value objectPREVIEW , it does does not have a monitor, an `IllegalMonitorStateException` is thrown.
  Throws:
    `IllegalMonitorStateException` - if the current thread is not the owner of this object's monitor or if this object is a value objectPREVIEW .
  See Also:
    - `notify()`
    - `wait()`
- =
  public java.lang.String toString()
- ≠
  public final void wait() throws java.lang.InterruptedException
  Comparing jdk-master and valhalla-csr-open

  ### wait

  public final void wait() throws InterruptedException
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted .

  In all respects, this method behaves as if `wait(0L, 0)` had been called. See the specification of the `wait(long, int)` method for details.

  If this object is a value objectPREVIEW , it does does not have a monitor, an `IllegalMonitorStateException` is thrown.
  Throws:
    `IllegalMonitorStateException` - if the current thread is not the owner of the object's monitor or if this object is a value objectPREVIEW .
    `InterruptedException` - if any thread interrupted the current thread before or while the current thread was waiting. The interrupted status of the current thread is cleared when this exception is thrown.
  See Also:
    - `notify()`
    - `notifyAll()`
    - `wait(long)`
    - `wait(long, int)`
- ≠
  public final void wait(long arg0) throws java.lang.InterruptedException
  Comparing jdk-master and valhalla-csr-open

  ### wait

  public final void wait (long timeoutMillis) throws InterruptedException
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted , or until a certain amount of real time has elapsed.

  In all respects, this method behaves as if `wait(timeoutMillis, 0)` had been called. See the specification of the `wait(long, int)` method for details.

  If this object is a value objectPREVIEW , it does does not have a monitor, an `IllegalMonitorStateException` is thrown.
  Parameters:
    `timeoutMillis` - the maximum time to wait, in milliseconds
  Throws:
    `IllegalArgumentException` - if `timeoutMillis` is negative
    `IllegalMonitorStateException` - if the current thread is not the owner of the object's monitor or if this object is a value objectPREVIEW .
    `InterruptedException` - if any thread interrupted the current thread before or while the current thread was waiting. The interrupted status of the current thread is cleared when this exception is thrown.
  See Also:
    - `notify()`
    - `notifyAll()`
    - `wait()`
    - `wait(long, int)`
- ≠
  public final void wait(long arg0, int arg1) throws java.lang.InterruptedException
  Comparing jdk-master and valhalla-csr-open

  ### wait

  public final void wait (long timeoutMillis, int nanos) throws InterruptedException
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted , or until a certain amount of real time has elapsed.

  The current thread must own this object's monitor lock. See the `notify` method for a description of the ways in which a thread can become the owner of a monitor lock.

  This method causes the current thread (referred to here as T ) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Note that only the locks on this object are relinquished; any other objects on which the current thread may be synchronized remain locked while the thread waits.

  Thread T then becomes disabled for thread scheduling purposes and lies dormant until one of the following occurs:

  - Some other thread invokes the `notify` method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
  - Some other thread invokes the `notifyAll` method for this object.
  - Some other thread interrupts thread T .
  - The specified amount of real time has elapsed, more or less. The amount of real time, in nanoseconds, is given by the expression `1000000 * timeoutMillis + nanos` . If `timeoutMillis` and `nanos` are both zero, then real time is not taken into consideration and the thread waits until awakened by one of the other causes.
  - Thread T is awakened spuriously. (See below.)

  The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It competes in the usual manner with other threads for the right to synchronize on the object; once it has regained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the `wait` method was invoked. Thread T then returns from the invocation of the `wait` method. Thus, on return from the `wait` method, the synchronization state of the object and of thread `T` is exactly as it was when the `wait` method was invoked.

  A thread can wake up without being notified, interrupted, or timing out, a so-called spurious wakeup . While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. See the example below.

  For more information on this topic, see section 14.2, "Condition Queues," in Brian Goetz and others' Java Concurrency in Practice (Addison-Wesley, 2006) or Item 81 in Joshua Bloch's Effective Java, Third Edition (Addison-Wesley, 2018).

  If the current thread is interrupted by any thread before or while it is waiting, then an `InterruptedException` is thrown. The interrupted status of the current thread is cleared when this exception is thrown. This exception is not thrown until the lock status of this object has been restored as described above.

  API Note:
    The recommended approach to waiting is to check the condition being awaited in a `while` loop around the call to `wait` , as shown in the example below. Among other things, this approach avoids problems that can be caused by spurious wakeups.

            synchronized (obj) {
                while ( <condition does not hold and timeout not exceeded> ) {
                    long timeoutMillis = ... ; // recompute timeout values
                    int nanos = ... ;
                    obj.wait(timeoutMillis, nanos);
                }
                ... // Perform action appropriate to condition or timeout
            }

    If this object is a value objectPREVIEW , it does does not have a monitor, an `IllegalMonitorStateException` is thrown.
  Parameters:
    `timeoutMillis` - the maximum time to wait, in milliseconds
    `nanos` - additional time, in nanoseconds, in the range 0-999999 inclusive
  Throws:
    `IllegalArgumentException` - if `timeoutMillis` is negative, or if the value of `nanos` is out of range
    `IllegalMonitorStateException` - if the current thread is not the owner of the object's monitor or if this object is a value objectPREVIEW .
    `InterruptedException` - if any thread interrupted the current thread before or while the current thread was waiting. The interrupted status of the current thread is cleared when this exception is thrown.
  See Also:
    - `notify()`
    - `notifyAll()`
    - `wait()`
    - `wait(long)`

## Summary

Differences
| Elements | Comments | Descriptions | Total
Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed
--- | --- | --- | --- | --- | --- | --- | --- | ---
Object |  |  |  |  |  |  |  | 1 |  | 1
notify() |  |  |  |  |  |  | 6 |  |  | 6
notifyAll() |  |  |  |  |  |  | 6 |  |  | 6
wait() |  |  |  |  |  |  | 8 |  |  | 8
wait(long) |  |  |  |  |  |  | 8 |  |  | 8
wait(long,int) |  |  |  |  |  |  | 9 |  |  | 9
Total |  |  |  |  |  |  | 37 | 1 |  | 38