< prev index next >

src/java.base/share/classes/java/lang/Object.java

Print this page

 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 
 28 import jdk.internal.HotSpotIntrinsicCandidate;
 29 
 30 /**
 31  * Class {@code Object} is the root of the class hierarchy.
 32  * Every class has {@code Object} as a superclass. All objects,
 33  * including arrays, implement the methods of this class.
 34  *
 35  * @author  unascribed
 36  * @see     java.lang.Class
 37  * @since   1.0
 38  */
 39 public class Object {
 40 
 41     /**
 42      * Constructs a new object.

 43      */
 44     @HotSpotIntrinsicCandidate
 45     public Object() {}
 46 
 47     /**




















 48      * Returns the runtime class of this {@code Object}. The returned
 49      * {@code Class} object is the object that is locked by {@code
 50      * static synchronized} methods of the represented class.
 51      *
 52      * <p><b>The actual result type is {@code Class<? extends |X|>}
 53      * where {@code |X|} is the erasure of the static type of the
 54      * expression on which {@code getClass} is called.</b> For
 55      * example, no cast is required in this code fragment:</p>
 56      *
 57      * <p>
 58      * {@code Number n = 0;                             }<br>
 59      * {@code Class<? extends Number> c = n.getClass(); }
 60      * </p>
 61      *
 62      * @return The {@code Class} object that represents the runtime
 63      *         class of this object.
 64      * @jls 15.8.2 Class Literals
 65      */
 66     @HotSpotIntrinsicCandidate
 67     public final native Class<?> getClass();

 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 
 28 import jdk.internal.HotSpotIntrinsicCandidate;
 29 
 30 /**
 31  * Class {@code Object} is the root of the class hierarchy.
 32  * Every class has {@code Object} as a superclass. All objects,
 33  * including arrays, implement the methods of this class.
 34  *
 35  * @author  unascribed
 36  * @see     java.lang.Class
 37  * @since   1.0
 38  */
 39 public class Object {
 40 
 41     /**
 42      * Constructs a new object.
 43      * @apiNote {@link Object#newIdentity} should be used instead of {@code new Object()}.
 44      */
 45     @HotSpotIntrinsicCandidate
 46     public Object() {}
 47 
 48     /**
 49      * Constructs a new Object implementing the IdentityObject interface.
 50      * The object is a unique IdentityObject suitable for all purposes
 51      * that previously for which {@code new Object{}} was used including synchronization,
 52      * mutexes and unique placeholders.
 53      *
 54      * @return a new Object implementing the IdentityObject interface
 55      * @since Valhalla
 56      */
 57     public static IdentityObject newIdentity() {
 58         return new IdentityInstance();
 59     }
 60 
 61     /**
 62      * IdentityInstance replaces plain {@code new Object()}.
 63      */
 64     private final static class IdentityInstance implements IdentityObject {
 65         private IdentityInstance() {}
 66     }
 67 
 68     /**
 69      * Returns the runtime class of this {@code Object}. The returned
 70      * {@code Class} object is the object that is locked by {@code
 71      * static synchronized} methods of the represented class.
 72      *
 73      * <p><b>The actual result type is {@code Class<? extends |X|>}
 74      * where {@code |X|} is the erasure of the static type of the
 75      * expression on which {@code getClass} is called.</b> For
 76      * example, no cast is required in this code fragment:</p>
 77      *
 78      * <p>
 79      * {@code Number n = 0;                             }<br>
 80      * {@code Class<? extends Number> c = n.getClass(); }
 81      * </p>
 82      *
 83      * @return The {@code Class} object that represents the runtime
 84      *         class of this object.
 85      * @jls 15.8.2 Class Literals
 86      */
 87     @HotSpotIntrinsicCandidate
 88     public final native Class<?> getClass();
< prev index next >