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.
java.lang.Class
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
protected native Object | |
public boolean | |
protected void | finalize()
Deprecated
for removal since 9. Finalization is deprecated and subject to removal in a future
release.
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
public final native Class | Returns: TheClass object that represents the runtime
class of this object.Returns the runtime class of this |
public native int | |
public final native void | |
public final native void | |
public String | Returns: a string representation of the objectReturns a string representation of the object. |
public final void | wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
public final void | wait(long
the maximum time to wait, in milliseconds timeoutMillis)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. |
public final void | wait(long
the maximum time to wait, in milliseconds timeoutMillis, int additional time, in nanoseconds, in the range 0-999999 inclusive nanos)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. |
private final native void |
Object | back to summary |
---|---|
public Object() Constructs a new object.
|
clone | back to summary |
---|---|
protected native Object clone() throws CloneNotSupportedException Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true , but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true , this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by Implementation Specification The method
The class
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. Implementation Specification The API Note It is generally necessary to override the The two-argument
|
finalize | back to summary |
---|---|
protected void finalize() throws Throwable
Deprecated for removal since 9. Finalization is deprecated and subject to removal in a future release. The use of finalization can lead to problems with security, performance, and reliability. See JEP 421 for discussion and alternatives.
Subclasses that override This method will remain in place until finalizers have been removed from most existing code. Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the
When running in a Java virtual machine in which finalization has been
disabled or removed, the garbage collector will never call
The general contract of
The
The Java programming language does not guarantee which thread will
invoke the
After the
The
Any exception thrown by the API Note Classes that embed non-heap resources have many options
for cleanup of those resources. The class must ensure that the
lifetime of each instance is longer than that of any resource it embeds.
A subclass should avoid overriding the @Override protected void finalize() throws Throwable { try { ... // cleanup subclass state } finally { super.finalize(); } }
|
getClass | back to summary |
---|---|
public final native Class Returns the runtime class of this The actual result type is
|
hashCode | back to summary |
---|---|
public native int hashCode() Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
Implementation Specification As far as is reasonably practical, the API Note The
|
notify | back to summary |
---|---|
public final native 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 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:
Only one thread at a time can own an object's monitor.
|
notifyAll | back to summary |
---|---|
public final native 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
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
|
toString | back to summary |
---|---|
public String toString() Returns a string representation of the object.
Satisfying this method's contract implies a non- API Note In general, the
Implementation Specification The getClass().getName() + '@' + Integer.toHexString(hashCode()) Objects. method returns the string for an
object equal to the string that would be returned if neither
the toString nor hashCode methods were
overridden by the object's class.
|
wait | back to summary |
---|---|
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 | back to summary |
---|---|
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 | back to summary |
---|---|
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
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:
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 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 API Note The recommended approach to waiting is to check the condition being awaited in
a 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 }
|
wait0 | back to summary |
---|---|
private final native void wait0(long timeoutMillis) throws InterruptedException |