1 *java.lang.Object* *Object* Class Object is the root of the class hierarchy.
6 |java.lang.Object_Description|
7 |java.lang.Object_Fields|
8 |java.lang.Object_Constructors|
9 |java.lang.Object_Methods|
11 ================================================================================
13 *java.lang.Object_Constructors*
16 *java.lang.Object_Methods*
17 |java.lang.Object.clone()|Creates and returns a copy of this object.
18 |java.lang.Object.equals(Object)|Indicates whether some other object is "equal
19 |java.lang.Object.finalize()|Called by the garbage collector on an object when
20 |java.lang.Object.getClass()|Returns the runtime class of thisObject.
21 |java.lang.Object.hashCode()|Returns a hash code value for the object.
22 |java.lang.Object.notify()|Wakes up a single thread that is waiting on this obj
23 |java.lang.Object.notifyAll()|Wakes up all threads that are waiting on this obj
24 |java.lang.Object.toString()|Returns a string representation of the object.
25 |java.lang.Object.wait()|Causes the current thread to wait until another thread
26 |java.lang.Object.wait(long)|Causes the current thread to wait until either ano
27 |java.lang.Object.wait(long,int)|Causes the current thread to wait until anothe
29 *java.lang.Object_Description*
31 Class Object is the root of the class hierarchy. Every class has Object as a
32 superclass. All objects, including arrays, implement the methods of this class.
43 *java.lang.Object.clone()*
45 protected native |java.lang.Object| clone()
46 throws |java.lang.CloneNotSupportedException|
48 Creates and returns a copy of this object. The precise meaning of "copy" may
49 depend on the class of the object. The general intent is that, for any object
56 will be true, and that the expression:
60 x.clone().getClass() == x.getClass()
62 will be true, but these are not absolute requirements. While it is typically
69 will be true, this is not an absolute requirement.
71 By convention, the returned object should be obtained by calling super.clone.
72 If a class and all of its superclasses (except Object) obey this convention, it
73 will be the case that x.clone().getClass() == x.getClass().
75 By convention, the object returned by this method should be independent of this
76 object (which is being cloned). To achieve this independence, it may be
77 necessary to modify one or more fields of the object returned by super.clone
78 before returning it. Typically, this means copying any mutable objects that
79 comprise the internal "deep structure" of the object being cloned and replacing
80 the references to these objects with references to the copies. If a class
81 contains only primitive fields or references to immutable objects, then it is
82 usually the case that no fields in the object returned by super.clone need to
85 The method clone for class Object performs a specific cloning operation. First,
86 if the class of this object does not implement the interface Cloneable, then a
87 CloneNotSupportedException is thrown. Note that all arrays are considered to
88 implement the interface Cloneable. Otherwise, this method creates a new
89 instance of the class of this object and initializes all its fields with
90 exactly the contents of the corresponding fields of this object, as if by
91 assignment; the contents of the fields are not themselves cloned. Thus, this
92 method performs a "shallow copy" of this object, not a "deep copy" operation.
94 The class Object does not itself implement the interface Cloneable, so calling
95 the clone method on an object whose class is Object will result in throwing an
96 exception at run time.
100 Returns: a clone of this instance.
102 *java.lang.Object.equals(Object)*
104 public boolean equals(java.lang.Object obj)
106 Indicates whether some other object is "equal to" this one.
108 The equals method implements an equivalence relation on non-null object
111 It is reflexive: for any non-null reference value x, x.equals(x) should return
112 true. It is symmetric: for any non-null reference values x and y, x.equals(y)
113 should return true if and only if y.equals(x) returns true. It is transitive:
114 for any non-null reference values x, y, and z, if x.equals(y) returns true and
115 y.equals(z) returns true, then x.equals(z) should return true. It is
116 consistent: for any non-null reference values x and y, multiple invocations of
117 x.equals(y) consistently return true or consistently return false, provided no
118 information used in equals comparisons on the objects is modified. For any
119 non-null reference value x, x.equals(null) should return false.
121 The equals method for class Object implements the most discriminating possible
122 equivalence relation on objects; that is, for any non-null reference values x
123 and y, this method returns true if and only if x and y refer to the same object
124 (x == y has the value true).
126 Note that it is generally necessary to override the hashCode method whenever
127 this method is overridden, so as to maintain the general contract for the
128 hashCode method, which states that equal objects must have equal hash codes.
131 obj - the reference object with which to compare.
133 Returns: true if this object is the same as the obj argument; false otherwise.
135 *java.lang.Object.finalize()*
137 protected void finalize()
138 throws |java.lang.Throwable|
140 Called by the garbage collector on an object when garbage collection determines
141 that there are no more references to the object. A subclass overrides the
142 finalize method to dispose of system resources or to perform other cleanup.
144 The general contract of finalize is that it is invoked if and when the JavaTM
145 virtual machine has determined that there is no longer any means by which this
146 object can be accessed by any thread that has not yet died, except as a result
147 of an action taken by the finalization of some other object or class which is
148 ready to be finalized. The finalize method may take any action, including
149 making this object available again to other threads; the usual purpose of
150 finalize, however, is to perform cleanup actions before the object is
151 irrevocably discarded. For example, the finalize method for an object that
152 represents an input/output connection might perform explicit I/O transactions
153 to break the connection before the object is permanently discarded.
155 The finalize method of class Object performs no special action; it simply
156 returns normally. Subclasses of Object may override this definition.
158 The Java programming language does not guarantee which thread will invoke the
159 finalize method for any given object. It is guaranteed, however, that the
160 thread that invokes finalize will not be holding any user-visible
161 synchronization locks when finalize is invoked. If an uncaught exception is
162 thrown by the finalize method, the exception is ignored and finalization of
163 that object terminates.
165 After the finalize method has been invoked for an object, no further action is
166 taken until the Java virtual machine has again determined that there is no
167 longer any means by which this object can be accessed by any thread that has
168 not yet died, including possible actions by other objects or classes which are
169 ready to be finalized, at which point the object may be discarded.
171 The finalize method is never invoked more than once by a Java virtual machine
172 for any given object.
174 Any exception thrown by the finalize method causes the finalization of this
175 object to be halted, but is otherwise ignored.
179 *java.lang.Object.getClass()*
181 public final native |java.lang.Class|<?> getClass()
183 Returns the runtime class of thisObject. The returnedClassobject is the object
184 that is locked bystatic synchronizedmethods of the represented class.
186 The actual result type isClasswhere|X|is the erasure of the static type of the
187 expression on whichgetClassis called. For example, no cast is required in this
190 Number n = 0;Class c = n.getClass();
194 Returns: The {@code Class} object that represents the runtime class of this object.
196 *java.lang.Object.hashCode()*
198 public native int hashCode()
200 Returns a hash code value for the object. This method is supported for the
201 benefit of hashtables such as those provided by java.util.Hashtable.
203 The general contract of hashCode is:
205 Whenever it is invoked on the same object more than once during an execution of
206 a Java application, the hashCode method must consistently return the same
207 integer, provided no information used in equals comparisons on the object is
208 modified. This integer need not remain consistent from one execution of an
209 application to another execution of the same application. If two objects are
210 equal according to the equals(Object) method, then calling the hashCode method
211 on each of the two objects must produce the same integer result. It is not
212 required that if two objects are unequal according to the (|java.lang.Object|)
213 method, then calling the hashCode method on each of the two objects must
214 produce distinct integer results. However, the programmer should be aware that
215 producing distinct integer results for unequal objects may improve the
216 performance of hashtables.
218 As much as is reasonably practical, the hashCode method defined by class Object
219 does return distinct integers for distinct objects. (This is typically
220 implemented by converting the internal address of the object into an integer,
221 but this implementation technique is not required by the JavaTM programming
226 Returns: a hash code value for this object.
228 *java.lang.Object.notify()*
230 public final native void notify()
232 Wakes up a single thread that is waiting on this object's monitor. If any
233 threads are waiting on this object, one of them is chosen to be awakened. The
234 choice is arbitrary and occurs at the discretion of the implementation. A
235 thread waits on an object's monitor by calling one of the wait methods.
237 The awakened thread will not be able to proceed until the current thread
238 relinquishes the lock on this object. The awakened thread will compete in the
239 usual manner with any other threads that might be actively competing to
240 synchronize on this object; for example, the awakened thread enjoys no reliable
241 privilege or disadvantage in being the next thread to lock this object.
243 This method should only be called by a thread that is the owner of this
244 object's monitor. A thread becomes the owner of the object's monitor in one of
247 By executing a synchronized instance method of that object. By executing the
248 body of a synchronized statement that synchronizes on the object. For objects
249 of type Class, by executing a synchronized static method of that class.
251 Only one thread at a time can own an object's monitor.
255 *java.lang.Object.notifyAll()*
257 public final native void notifyAll()
259 Wakes up all threads that are waiting on this object's monitor. A thread waits
260 on an object's monitor by calling one of the wait methods.
262 The awakened threads will not be able to proceed until the current thread
263 relinquishes the lock on this object. The awakened threads will compete in the
264 usual manner with any other threads that might be actively competing to
265 synchronize on this object; for example, the awakened threads enjoy no reliable
266 privilege or disadvantage in being the next thread to lock this object.
268 This method should only be called by a thread that is the owner of this
269 object's monitor. See the notify method for a description of the ways in which
270 a thread can become the owner of a monitor.
274 *java.lang.Object.toString()*
276 public |java.lang.String| toString()
278 Returns a string representation of the object. In general, the toString method
279 returns a string that "textually represents" this object. The result should be
280 a concise but informative representation that is easy for a person to read. It
281 is recommended that all subclasses override this method.
283 The toString method for class Object returns a string consisting of the name of
284 the class of which the object is an instance, the at-sign character `@', and
285 the unsigned hexadecimal representation of the hash code of the object. In
286 other words, this method returns a string equal to the value of:
290 getClass().getName() + '@' + Integer.toHexString(hashCode())
294 Returns: a string representation of the object.
296 *java.lang.Object.wait()*
298 public final void wait()
299 throws |java.lang.InterruptedException|
301 Causes the current thread to wait until another thread invokes the
302 (|java.lang.Object|) method or the (|java.lang.Object|) method for this object.
303 In other words, this method behaves exactly as if it simply performs the call
306 The current thread must own this object's monitor. The thread releases
307 ownership of this monitor and waits until another thread notifies threads
308 waiting on this object's monitor to wake up either through a call to the notify
309 method or the notifyAll method. The thread then waits until it can re-obtain
310 ownership of the monitor and resumes execution.
312 As in the one argument version, interrupts and spurious wakeups are possible,
313 and this method should always be used in a loop:
315 synchronized (obj) { while (<condition does not hold>) obj.wait(); ... //
316 Perform action appropriate to condition }
318 This method should only be called by a thread that is the owner of this
319 object's monitor. See the notify method for a description of the ways in which
320 a thread can become the owner of a monitor.
324 *java.lang.Object.wait(long)*
326 public final native void wait(long timeout)
327 throws |java.lang.InterruptedException|
329 Causes the current thread to wait until either another thread invokes the
330 (|java.lang.Object|) method or the (|java.lang.Object|) method for this object,
331 or a specified amount of time has elapsed.
333 The current thread must own this object's monitor.
335 This method causes the current thread (call it T) to place itself in the wait
336 set for this object and then to relinquish any and all synchronization claims
337 on this object. Thread T becomes disabled for thread scheduling purposes and
338 lies dormant until one of four things happens:
340 Some other thread invokes the notify method for this object and thread T
341 happens to be arbitrarily chosen as the thread to be awakened. Some other
342 thread invokes the notifyAll method for this object. Some other thread
343 interrupts(|java.lang.Thread|) thread T. The specified amount of real time has
344 elapsed, more or less. If timeout is zero, however, then real time is not taken
345 into consideration and the thread simply waits until notified.
347 The thread T is then removed from the wait set for this object and re-enabled
348 for thread scheduling. It then competes in the usual manner with other threads
349 for the right to synchronize on the object; once it has gained control of the
350 object, all its synchronization claims on the object are restored to the status
351 quo ante - that is, to the situation as of the time that the wait method was
352 invoked. Thread T then returns from the invocation of the wait method. Thus, on
353 return from the wait method, the synchronization state of the object and of
354 thread T is exactly as it was when the wait method was invoked.
356 A thread can also wake up without being notified, interrupted, or timing out, a
357 so-called spurious wakeup. While this will rarely occur in practice,
358 applications must guard against it by testing for the condition that should
359 have caused the thread to be awakened, and continuing to wait if the condition
360 is not satisfied. In other words, waits should always occur in loops, like this
363 synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ...
364 // Perform action appropriate to condition }
366 (For more information on this topic, see Section 3.2.3 in Doug Lea's
367 "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or
368 Item 50 in Joshua Bloch's "Effective Java Programming Language Guide"
369 (Addison-Wesley, 2001).
371 If the current thread is interrupted(|java.lang.Thread|) by any thread before
372 or while it is waiting, then an InterruptedException is thrown. This exception
373 is not thrown until the lock status of this object has been restored as
376 Note that the wait method, as it places the current thread into the wait set
377 for this object, unlocks only this object; any other objects on which the
378 current thread may be synchronized remain locked while the thread waits.
380 This method should only be called by a thread that is the owner of this
381 object's monitor. See the notify method for a description of the ways in which
382 a thread can become the owner of a monitor.
385 timeout - the maximum time to wait in milliseconds.
387 *java.lang.Object.wait(long,int)*
389 public final void wait(
392 throws |java.lang.InterruptedException|
394 Causes the current thread to wait until another thread invokes the
395 (|java.lang.Object|) method or the (|java.lang.Object|) method for this object,
396 or some other thread interrupts the current thread, or a certain amount of real
399 This method is similar to the wait method of one argument, but it allows finer
400 control over the amount of time to wait for a notification before giving up.
401 The amount of real time, measured in nanoseconds, is given by:
405 1000000*timeout+nanos
407 In all other respects, this method does the same thing as the method
408 (|java.lang.Object|) of one argument. In particular, wait(0, 0) means the same
411 The current thread must own this object's monitor. The thread releases
412 ownership of this monitor and waits until either of the following two
413 conditions has occurred:
415 Another thread notifies threads waiting on this object's monitor to wake up
416 either through a call to the notify method or the notifyAll method. The timeout
417 period, specified by timeout milliseconds plus nanos nanoseconds arguments, has
420 The thread then waits until it can re-obtain ownership of the monitor and
423 As in the one argument version, interrupts and spurious wakeups are possible,
424 and this method should always be used in a loop:
426 synchronized (obj) { while (<condition does not hold>) obj.wait(timeout,
427 nanos); ... // Perform action appropriate to condition }
429 This method should only be called by a thread that is the owner of this
430 object's monitor. See the notify method for a description of the ways in which
431 a thread can become the owner of a monitor.
434 timeout - the maximum time to wait in milliseconds.
435 nanos - additional time, in nanoseconds range 0-999999.