< prev index next >

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

Print this page
*** 24,10 ***
--- 24,13 ---
   */
  
  package java.lang;
  
  import jdk.internal.vm.annotation.IntrinsicCandidate;
+ import jdk.internal.access.SharedSecrets;
+ 
+ import java.util.Objects;
  
  /**
   * Class {@code Object} is the root of the class hierarchy.
   * Every class has {@code Object} as a superclass. All objects,
   * including arrays, implement the methods of this class.

*** 37,10 ***
--- 40,13 ---
   */
  public class Object {
  
      /**
       * Constructs a new object.
+      *
+      * @apiNote {@link Objects#newIdentity java.util.Objects.newIdentity()}
+      * should be used instead of {@code new Object()}.
       */
      @IntrinsicCandidate
      public Object() {}
  
      /**

*** 237,20 ***
       * person to read.
       * It is recommended that all subclasses override this method.
       * The string output is not necessarily stable over time or across
       * JVM invocations.
       * @implSpec
!      * The {@code toString} method for class {@code Object}
       * returns a string consisting of the name of the class of which the
       * object is an instance, the at-sign character `{@code @}', and
       * the unsigned hexadecimal representation of the hash code of the
       * object. In other words, this method returns a string equal to the
       * value of:
       * <blockquote>
       * <pre>
       * getClass().getName() + '@' + Integer.toHexString(hashCode())
       * </pre></blockquote>
       *
       * @return  a string representation of the object.
       */
      public String toString() {
          return getClass().getName() + "@" + Integer.toHexString(hashCode());
--- 243,27 ---
       * person to read.
       * It is recommended that all subclasses override this method.
       * The string output is not necessarily stable over time or across
       * JVM invocations.
       * @implSpec
!      * If this object is an instance of an identity class, then
+      * the {@code toString} method for class {@code Object}
       * returns a string consisting of the name of the class of which the
       * object is an instance, the at-sign character `{@code @}', and
       * the unsigned hexadecimal representation of the hash code of the
       * object. In other words, this method returns a string equal to the
       * value of:
       * <blockquote>
       * <pre>
       * getClass().getName() + '@' + Integer.toHexString(hashCode())
       * </pre></blockquote>
+      * <p>
+      * If this object is an instance of a primitive class, then
+      * the {@code toString} method returns a string which contains
+      * the name of the primitive class, and string representations of
+      * all its fields.  The precise format produced by this method
+      * is unspecified and subject to change.
       *
       * @return  a string representation of the object.
       */
      public String toString() {
          return getClass().getName() + "@" + Integer.toHexString(hashCode());
< prev index next >