jdk/src/java.base/share/classes/java/lang/Object.java
author darcy
Thu, 29 Jan 2015 16:16:35 -0800
changeset 28685 6e8154707178
parent 28683 a36c179aa292
child 31671 362e0c0acece
permissions -rw-r--r--
8071959: java.lang.Object uses implicit default constructor Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28683
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
     2
 * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1937
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1937
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1937
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1937
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1937
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    29
 * Class {@code Object} is the root of the class hierarchy.
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    30
 * Every class has {@code Object} as a superclass. All objects,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * including arrays, implement the methods of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see     java.lang.Class
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 14342
diff changeset
    35
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class Object {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static native void registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
28685
6e8154707178 8071959: java.lang.Object uses implicit default constructor
darcy
parents: 28683
diff changeset
    45
     * Constructs a new object.
6e8154707178 8071959: java.lang.Object uses implicit default constructor
darcy
parents: 28683
diff changeset
    46
     */
6e8154707178 8071959: java.lang.Object uses implicit default constructor
darcy
parents: 28683
diff changeset
    47
    public Object() {}
6e8154707178 8071959: java.lang.Object uses implicit default constructor
darcy
parents: 28683
diff changeset
    48
6e8154707178 8071959: java.lang.Object uses implicit default constructor
darcy
parents: 28683
diff changeset
    49
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Returns the runtime class of this {@code Object}. The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * {@code Class} object is the object that is locked by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * static synchronized} methods of the represented class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * <p><b>The actual result type is {@code Class<? extends |X|>}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * where {@code |X|} is the erasure of the static type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * expression on which {@code getClass} is called.</b> For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * example, no cast is required in this code fragment:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * {@code Number n = 0;                             }<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * {@code Class<? extends Number> c = n.getClass(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @return The {@code Class} object that represents the runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *         class of this object.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
    66
     * @jls 15.8.2 Class Literals
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public final native Class<?> getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns a hash code value for the object. This method is
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    72
     * supported for the benefit of hash tables such as those provided by
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    73
     * {@link java.util.HashMap}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    75
     * The general contract of {@code hashCode} is:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <li>Whenever it is invoked on the same object more than once during
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    78
     *     an execution of a Java application, the {@code hashCode} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *     must consistently return the same integer, provided no information
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    80
     *     used in {@code equals} comparisons on the object is modified.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *     This integer need not remain consistent from one execution of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *     application to another execution of the same application.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    83
     * <li>If two objects are equal according to the {@code equals(Object)}
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    84
     *     method, then calling the {@code hashCode} method on each of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *     the two objects must produce the same integer result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <li>It is <em>not</em> required that if two objects are unequal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    88
     *     method, then calling the {@code hashCode} method on each of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *     two objects must produce distinct integer results.  However, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *     programmer should be aware that producing distinct integer results
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
    91
     *     for unequal objects may improve the performance of hash tables.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <p>
28683
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
    94
     * As much as is reasonably practical, the hashCode method defined
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
    95
     * by class {@code Object} does return distinct integers for
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
    96
     * distinct objects. (The hashCode may or may not be implemented
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
    97
     * as some function of an object's memory address at some point
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
    98
     * in time.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return  a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see     java.lang.Object#equals(java.lang.Object)
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   102
     * @see     java.lang.System#identityHashCode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public native int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Indicates whether some other object is "equal to" this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   109
     * The {@code equals} method implements an equivalence relation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * on non-null object references:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <li>It is <i>reflexive</i>: for any non-null reference value
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   113
     *     {@code x}, {@code x.equals(x)} should return
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   114
     *     {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <li>It is <i>symmetric</i>: for any non-null reference values
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   116
     *     {@code x} and {@code y}, {@code x.equals(y)}
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   117
     *     should return {@code true} if and only if
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   118
     *     {@code y.equals(x)} returns {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <li>It is <i>transitive</i>: for any non-null reference values
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   120
     *     {@code x}, {@code y}, and {@code z}, if
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   121
     *     {@code x.equals(y)} returns {@code true} and
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   122
     *     {@code y.equals(z)} returns {@code true}, then
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   123
     *     {@code x.equals(z)} should return {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <li>It is <i>consistent</i>: for any non-null reference values
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   125
     *     {@code x} and {@code y}, multiple invocations of
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   126
     *     {@code x.equals(y)} consistently return {@code true}
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   127
     *     or consistently return {@code false}, provided no
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   128
     *     information used in {@code equals} comparisons on the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *     objects is modified.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   130
     * <li>For any non-null reference value {@code x},
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   131
     *     {@code x.equals(null)} should return {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   134
     * The {@code equals} method for class {@code Object} implements
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * the most discriminating possible equivalence relation on objects;
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   136
     * that is, for any non-null reference values {@code x} and
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   137
     * {@code y}, this method returns {@code true} if and only
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   138
     * if {@code x} and {@code y} refer to the same object
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   139
     * ({@code x == y} has the value {@code true}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   141
     * Note that it is generally necessary to override the {@code hashCode}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * method whenever this method is overridden, so as to maintain the
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   143
     * general contract for the {@code hashCode} method, which states
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * that equal objects must have equal hash codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param   obj   the reference object with which to compare.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   147
     * @return  {@code true} if this object is the same as the obj
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   148
     *          argument; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see     #hashCode()
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   150
     * @see     java.util.HashMap
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return (this == obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Creates and returns a copy of this object.  The precise meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * of "copy" may depend on the class of the object. The general
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   159
     * intent is that, for any object {@code x}, the expression:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * x.clone() != x</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * will be true, and that the expression:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * x.clone().getClass() == x.getClass()</pre></blockquote>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   167
     * will be {@code true}, but these are not absolute requirements.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * While it is typically the case that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * x.clone().equals(x)</pre></blockquote>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   172
     * will be {@code true}, this is not an absolute requirement.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * By convention, the returned object should be obtained by calling
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   175
     * {@code super.clone}.  If a class and all of its superclasses (except
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   176
     * {@code Object}) obey this convention, it will be the case that
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   177
     * {@code x.clone().getClass() == x.getClass()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * By convention, the object returned by this method should be independent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * of this object (which is being cloned).  To achieve this independence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * it may be necessary to modify one or more fields of the object returned
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   182
     * by {@code super.clone} before returning it.  Typically, this means
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * copying any mutable objects that comprise the internal "deep structure"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * of the object being cloned and replacing the references to these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * objects with references to the copies.  If a class contains only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * primitive fields or references to immutable objects, then it is usually
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   187
     * the case that no fields in the object returned by {@code super.clone}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * need to be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   190
     * The method {@code clone} for class {@code Object} performs a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * specific cloning operation. First, if the class of this object does
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   192
     * not implement the interface {@code Cloneable}, then a
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   193
     * {@code CloneNotSupportedException} is thrown. Note that all arrays
6527
352bf578a6dd 4881419: The type of X[].clone() should be X[]
darcy
parents: 5506
diff changeset
   194
     * are considered to implement the interface {@code Cloneable} and that
352bf578a6dd 4881419: The type of X[].clone() should be X[]
darcy
parents: 5506
diff changeset
   195
     * the return type of the {@code clone} method of an array type {@code T[]}
352bf578a6dd 4881419: The type of X[].clone() should be X[]
darcy
parents: 5506
diff changeset
   196
     * is {@code T[]} where T is any reference or primitive type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Otherwise, this method creates a new instance of the class of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * object and initializes all its fields with exactly the contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * the corresponding fields of this object, as if by assignment; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * contents of the fields are not themselves cloned. Thus, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * performs a "shallow copy" of this object, not a "deep copy" operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   203
     * The class {@code Object} does not itself implement the interface
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   204
     * {@code Cloneable}, so calling the {@code clone} method on an object
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   205
     * whose class is {@code Object} will result in throwing an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * exception at run time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return     a clone of this instance.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   209
     * @throws  CloneNotSupportedException  if the object's class does not
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   210
     *               support the {@code Cloneable} interface. Subclasses
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   211
     *               that override the {@code clone} method can also
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *               throw this exception to indicate that an instance cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *               be cloned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    protected native Object clone() throws CloneNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns a string representation of the object. In general, the
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   220
     * {@code toString} method returns a string that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * "textually represents" this object. The result should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * be a concise but informative representation that is easy for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * person to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * It is recommended that all subclasses override this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   226
     * The {@code toString} method for class {@code Object}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * returns a string consisting of the name of the class of which the
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   228
     * object is an instance, the at-sign character `{@code @}', and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * the unsigned hexadecimal representation of the hash code of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * object. In other words, this method returns a string equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * value of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * getClass().getName() + '@' + Integer.toHexString(hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return  a string representation of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Wakes up a single thread that is waiting on this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * monitor. If any threads are waiting on this object, one of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * is chosen to be awakened. The choice is arbitrary and occurs at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * the discretion of the implementation. A thread waits on an object's
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   248
     * monitor by calling one of the {@code wait} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * The awakened thread will not be able to proceed until the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * thread relinquishes the lock on this object. The awakened thread will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * compete in the usual manner with any other threads that might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * actively competing to synchronize on this object; for example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * awakened thread enjoys no reliable privilege or disadvantage in being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the next thread to lock this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * of this object's monitor. A thread becomes the owner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * object's monitor in one of three ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <li>By executing a synchronized instance method of that object.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   262
     * <li>By executing the body of a {@code synchronized} statement
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *     that synchronizes on the object.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   264
     * <li>For objects of type {@code Class,} by executing a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *     synchronized static method of that class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Only one thread at a time can own an object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   270
     * @throws  IllegalMonitorStateException  if the current thread is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *               the owner of this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see        java.lang.Object#wait()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public final native void notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Wakes up all threads that are waiting on this object's monitor. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * thread waits on an object's monitor by calling one of the
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   280
     * {@code wait} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * The awakened threads will not be able to proceed until the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * thread relinquishes the lock on this object. The awakened threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * will compete in the usual manner with any other threads that might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * be actively competing to synchronize on this object; for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * the awakened threads enjoy no reliable privilege or disadvantage in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * being the next thread to lock this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * This method should only be called by a thread that is the owner
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   290
     * of this object's monitor. See the {@code notify} method for a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   294
     * @throws  IllegalMonitorStateException  if the current thread is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *               the owner of this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see        java.lang.Object#wait()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public final native void notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Causes the current thread to wait until either another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * {@link java.lang.Object#notifyAll()} method for this object, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * specified amount of time has elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * The current thread must own this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * This method causes the current thread (call it <var>T</var>) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * place itself in the wait set for this object and then to relinquish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * any and all synchronization claims on this object. Thread <var>T</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * becomes disabled for thread scheduling purposes and lies dormant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * until one of four things happens:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <ul>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   315
     * <li>Some other thread invokes the {@code notify} method for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * object and thread <var>T</var> happens to be arbitrarily chosen as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * the thread to be awakened.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   318
     * <li>Some other thread invokes the {@code notifyAll} method for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * thread <var>T</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <li>The specified amount of real time has elapsed, more or less.  If
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   323
     * {@code timeout} is zero, however, then real time is not taken into
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * consideration and the thread simply waits until notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * The thread <var>T</var> is then removed from the wait set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * object and re-enabled for thread scheduling. It then competes in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * usual manner with other threads for the right to synchronize on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * object; once it has gained control of the object, all its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * synchronization claims on the object are restored to the status quo
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   331
     * ante - that is, to the situation as of the time that the {@code wait}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * method was invoked. Thread <var>T</var> then returns from the
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   333
     * invocation of the {@code wait} method. Thus, on return from the
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   334
     * {@code wait} method, the synchronization state of the object and of
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   335
     * thread {@code T} is exactly as it was when the {@code wait} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * A thread can also wake up without being notified, interrupted, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * occur in practice, applications must guard against it by testing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * the condition that should have caused the thread to be awakened, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * continuing to wait if the condition is not satisfied.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * waits should always occur in loops, like this one:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *             obj.wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * </pre>
28683
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   351
     *
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   352
     * (For more information on this topic, see section 14.2,
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   353
     * Condition Queues, in Brian Goetz and others' "Java Concurrency
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   354
     * in Practice" (Addison-Wesley, 2006) or Item 69 in Joshua
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   355
     * Bloch's "Effective Java (Second Edition)" (Addison-Wesley,
a36c179aa292 8071434: doc updates for java.lang.Object
darcy
parents: 27733
diff changeset
   356
     * 2008).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * interrupted} by any thread before or while it is waiting, then an
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   360
     * {@code InterruptedException} is thrown.  This exception is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * thrown until the lock status of this object has been restored as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   365
     * Note that the {@code wait} method, as it places the current thread
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * into the wait set for this object, unlocks only this object; any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * other objects on which the current thread may be synchronized remain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * locked while the thread waits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * This method should only be called by a thread that is the owner
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   371
     * of this object's monitor. See the {@code notify} method for a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param      timeout   the maximum time to wait in milliseconds.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   376
     * @throws  IllegalArgumentException      if the value of timeout is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *               negative.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   378
     * @throws  IllegalMonitorStateException  if the current thread is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *               the owner of the object's monitor.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   380
     * @throws  InterruptedException if any thread interrupted the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public final native void wait(long timeout) throws InterruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Causes the current thread to wait until another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * {@link java.lang.Object#notifyAll()} method for this object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * some other thread interrupts the current thread, or a certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * amount of real time has elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   397
     * This method is similar to the {@code wait} method of one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * argument, but it allows finer control over the amount of time to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * wait for a notification before giving up. The amount of real time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * measured in nanoseconds, is given by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * 1000000*timeout+nanos</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * In all other respects, this method does the same thing as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * method {@link #wait(long)} of one argument. In particular,
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   407
     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * The current thread must own this object's monitor. The thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * releases ownership of this monitor and waits until either of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * following two conditions has occurred:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <li>Another thread notifies threads waiting on this object's monitor
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   414
     *     to wake up either through a call to the {@code notify} method
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   415
     *     or the {@code notifyAll} method.
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   416
     * <li>The timeout period, specified by {@code timeout}
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   417
     *     milliseconds plus {@code nanos} nanoseconds arguments, has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *     elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * The thread then waits until it can re-obtain ownership of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * monitor and resumes execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * As in the one argument version, interrupts and spurious wakeups are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * possible, and this method should always be used in a loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *             obj.wait(timeout, nanos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * This method should only be called by a thread that is the owner
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   434
     * of this object's monitor. See the {@code notify} method for a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param      timeout   the maximum time to wait in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param      nanos      additional time, in nanoseconds range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *                       0-999999.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   441
     * @throws  IllegalArgumentException      if the value of timeout is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *                      negative or the value of nanos is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *                      not in the range 0-999999.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   444
     * @throws  IllegalMonitorStateException  if the current thread is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *               the owner of this object's monitor.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   446
     * @throws  InterruptedException if any thread interrupted the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public final void wait(long timeout, int nanos) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (timeout < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            throw new IllegalArgumentException("timeout value is negative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (nanos < 0 || nanos > 999999) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                "nanosecond timeout value out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
27733
e4e4d12307d7 8065372: Object.wait(ms, ns) timeout returns early
rriggs
parents: 25859
diff changeset
   462
        if (nanos > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            timeout++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Causes the current thread to wait until another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * {@link java.lang.Object#notifyAll()} method for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * In other words, this method behaves exactly as if it simply
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   474
     * performs the call {@code wait(0)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * The current thread must own this object's monitor. The thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * releases ownership of this monitor and waits until another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * notifies threads waiting on this object's monitor to wake up
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   479
     * either through a call to the {@code notify} method or the
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   480
     * {@code notifyAll} method. The thread then waits until it can
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * re-obtain ownership of the monitor and resumes execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * As in the one argument version, interrupts and spurious wakeups are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * possible, and this method should always be used in a loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *             obj.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * This method should only be called by a thread that is the owner
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   493
     * of this object's monitor. See the {@code notify} method for a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   497
     * @throws  IllegalMonitorStateException  if the current thread is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *               the owner of the object's monitor.
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   499
     * @throws  InterruptedException if any thread interrupted the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public final void wait() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        wait(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Called by the garbage collector on an object when garbage collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * determines that there are no more references to the object.
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   514
     * A subclass overrides the {@code finalize} method to dispose of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * system resources or to perform other cleanup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   517
     * The general contract of {@code finalize} is that it is invoked
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   518
     * if and when the Java&trade; virtual
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * machine has determined that there is no longer any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * means by which this object can be accessed by any thread that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * not yet died, except as a result of an action taken by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * finalization of some other object or class which is ready to be
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   523
     * finalized. The {@code finalize} method may take any action, including
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * making this object available again to other threads; the usual purpose
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   525
     * of {@code finalize}, however, is to perform cleanup actions before
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * the object is irrevocably discarded. For example, the finalize method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * for an object that represents an input/output connection might perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * explicit I/O transactions to break the connection before the object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * permanently discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   531
     * The {@code finalize} method of class {@code Object} performs no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * special action; it simply returns normally. Subclasses of
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   533
     * {@code Object} may override this definition.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * The Java programming language does not guarantee which thread will
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   536
     * invoke the {@code finalize} method for any given object. It is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * guaranteed, however, that the thread that invokes finalize will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * be holding any user-visible synchronization locks when finalize is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * invoked. If an uncaught exception is thrown by the finalize method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * the exception is ignored and finalization of that object terminates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   542
     * After the {@code finalize} method has been invoked for an object, no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * further action is taken until the Java virtual machine has again
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * determined that there is no longer any means by which this object can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * be accessed by any thread that has not yet died, including possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * actions by other objects or classes which are ready to be finalized,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * at which point the object may be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   549
     * The {@code finalize} method is never invoked more than once by a Java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * virtual machine for any given object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <p>
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   552
     * Any exception thrown by the {@code finalize} method causes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * the finalization of this object to be halted, but is otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
1937
28c31d4a9597 6239194: Object.hashCode() should reference System.identityHashCode()
darcy
parents: 2
diff changeset
   556
     * @throws Throwable the {@code Exception} raised by this method
11516
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   557
     * @see java.lang.ref.WeakReference
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   558
     * @see java.lang.ref.PhantomReference
0e4924734eed 7112008: Javadoc for j.l.Object.finalize() vs JLS 12.6 Finalization of Class Instances
darcy
parents: 9266
diff changeset
   559
     * @jls 12.6 Finalization of Class Instances
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    protected void finalize() throws Throwable { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
}