📄 object.java
字号:
* @see #wait(long) * @see Thread */ public final native void wait(long timeout, int nanos) throws InterruptedException; /** * Determine whether this Object is semantically equal * to another Object. * * <p>There are some fairly strict requirements on this * method which subclasses must follow:<br> * <ul> * <li>It must be transitive. If <code>a.equals(b)</code> and * <code>b.equals(c)</code>, then <code>a.equals(c)</code> * must be true as well.</li> * <li>It must be symmetric. <code>a.equals(b)</code> and * <code>b.equals(a)</code> must have the same value.</li> * <li>It must be reflexive. <code>a.equals(a)</code> must * always be true.</li> * <li>It must be consistent. Whichever value a.equals(b) * returns on the first invocation must be the value * returned on all later invocations.</li> * <li><code>a.equals(null)</code> must be false.</li> * <li>It must be consistent with hashCode(). That is, * <code>a.equals(b)</code> must imply * <code>a.hashCode() == b.hashCode()</code>. * The reverse is not true; two objects that are not * equal may have the same hashcode, but that has * the potential to harm hashing performance.</li> * </ul> * * <p>This is typically overridden to throw a {@link ClassCastException} * if the argument is not comparable to the class performing * the comparison, but that is not a requirement. It is legal * for <code>a.equals(b)</code> to be true even though * <code>a.getClass() != b.getClass()</code>. Also, it * is typical to never cause a {@link NullPointerException}. * * <p>In general, the Collections API ({@link java.util}) use the * <code>equals</code> method rather than the <code>==</code> * operator to compare objects. However, {@link java.util.IdentityHashMap} * is an exception to this rule, for its own good reasons. * * <p>The default implementation returns <code>this == o</code>. * * @param obj the Object to compare to * @return whether this Object is semantically equal to another * @see #hashCode() */ public boolean equals(Object obj) { return this == obj; } /** * The basic constructor. Object is special, because it has no * superclass, so there is no call to super(). * * @throws OutOfMemoryError Technically, this constructor never * throws an OutOfMemoryError, because the memory has * already been allocated by this point. But as all * instance creation expressions eventually trace back * to this constructor, and creating an object allocates * memory, we list that possibility here. */ public Object() { } /** * Convert this Object to a human-readable String. * There are no limits placed on how long this String * should be or what it should contain. We suggest you * make it as intuitive as possible to be able to place * it into {@link java.io.PrintStream#println() System.out.println()} * and such. * * <p>It is typical, but not required, to ensure that this method * never completes abruptly with a {@link RuntimeException}. * * <p>This method will be called when performing string * concatenation with this object. If the result is * <code>null</code>, string concatenation will instead * use <code>"null"</code>. * * <p>The default implementation returns * <code>getClass().getName() + "@" + * Integer.toHexString(hashCode())</code>. * * @return the String representing this Object, which may be null * @throws OutOfMemoryError The default implementation creates a new * String object, therefore it must allocate memory * @see #getClass() * @see #hashCode() * @see Class#getName() * @see Integer#toHexString(int) */ public String toString() { return getClass().getName() + '@' + Integer.toHexString(hashCode()); } /** * Waits indefinitely for notify() or notifyAll() to be * called on the Object in question. Implementation is * identical to wait(0). * * <p>The Thread that calls wait must have a lock on this Object, * obtained by a <code>synchronized</code> method or statement. * After calling wait, the thread loses the lock on this * object until the method completes (abruptly or normally), * at which time it regains the lock. All locks held on * other objects remain in force, even though the thread is * inactive. Therefore, caution must be used to avoid deadlock. * * <p>While it is typical that this method will complete abruptly * with an {@link InterruptedException}, it is not guaranteed. So, * it is typical to call wait inside an infinite loop:<br> * * <pre> * try * { * while (true) * lock.wait(); * } * catch (InterruptedException e) * { * } * </pre> * * @throws IllegalMonitorStateException if this Thread * does not own a lock on this Object * @throws InterruptedException if some other Thread * interrupts this Thread * @see #notify() * @see #notifyAll() * @see #wait(long) * @see #wait(long, int) * @see Thread */ public final void wait() throws InterruptedException { wait(0, 0); } /** * Waits a specified amount of time (or indefinitely if * the time specified is 0) for someone to call notify() * or notifyAll() on this Object, waking up this Thread. * * <p>The Thread that calls wait must have a lock on this Object, * obtained by a <code>synchronized</code> method or statement. * After calling wait, the thread loses the lock on this * object until the method completes (abruptly or normally), * at which time it regains the lock. All locks held on * other objects remain in force, even though the thread is * inactive. Therefore, caution must be used to avoid deadlock. * * <p>Usually, this call will complete normally if the time * expires, or abruptly with {@link InterruptedException} * if another thread called notify, but neither result * is guaranteed. * * <p>The waiting period is only *roughly* the amount of time * you requested. It cannot be exact because of the overhead * of the call itself. Most Virtual Machiness treat the * argument as a lower limit on the time spent waiting, but * even that is not guaranteed. Besides, some other thread * may hold the lock on the object when the time expires, so * the current thread may still have to wait to reobtain the * lock. * * @param timeout the minimum number of milliseconds to wait (1000 * milliseconds = 1 second), or 0 for an indefinite wait * @throws IllegalArgumentException if ms < 0 * @throws IllegalMonitorStateException if this Thread * does not own a lock on this Object * @throws InterruptedException if some other Thread * interrupts this Thread * @see #notify() * @see #notifyAll() * @see #wait() * @see #wait(long, int) * @see Thread */ public final void wait(long timeout) throws InterruptedException { wait(timeout, 0); } /** * This method may be called to create a new copy of the * Object. The typical behavior is as follows:<br> * <ul> * <li><code>o == o.clone()</code> is false</li> * <li><code>o.getClass() == o.clone().getClass()</code> * is true</li> * <li><code>o.equals(o)</code> is true</li> * </ul> * * <p>However, these are not strict requirements, and may * be violated if necessary. Of the three requirements, the * last is the most commonly violated, particularly if the * subclass does not override {@link #equals(Object)}. * * <p>If the Object you call clone() on does not implement * {@link Cloneable} (which is a placeholder interface), then * a CloneNotSupportedException is thrown. Notice that * Object does not implement Cloneable; this method exists * as a convenience for subclasses that do. * * <p>Object's implementation of clone allocates space for the * new Object using the correct class, without calling any * constructors, and then fills in all of the new field values * with the old field values. Thus, it is a shallow copy. * However, subclasses are permitted to make a deep copy. * * <p>All array types implement Cloneable, and override * this method as follows (it should never fail):<br> * <pre> * public Object clone() * { * try * { * super.clone(); * } * catch (CloneNotSupportedException e) * { * throw new InternalError(e.getMessage()); * } * } * </pre> * * @return a copy of the Object * @throws CloneNotSupportedException If this Object does not * implement Cloneable * @throws OutOfMemoryError Since cloning involves memory allocation, * even though it may bypass constructors, you might run * out of memory * @see Cloneable */ protected native Object clone() throws CloneNotSupportedException; // This initializes the sync_info member. It is here for // completeness (some day we'll be able to auto-generate Object.h). private final native void sync_init(); // If we fail to find a method at class loading time we put the // vtable index of this method in its place: any attempt to call // that method will result in an error. void throwNoSuchMethodError() { throw new NoSuchMethodError("in " + getClass()); } // Note that we don't mention the sync_info field here. If we do, // jc1 will not work correctly.}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -