Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/java.base/share/classes/java/lang/Object.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -67,7 +67,7 @@ public Object() {}
public final native Class<?> getClass();

/**
* Returns a hash code value for the object. This method is
* {@return a hash code value for this object} This method is
* supported for the benefit of hash tables such as those provided by
* {@link java.util.HashMap}.
* <p>
Expand Down Expand Up @@ -95,7 +95,11 @@ public Object() {}
* As far as is reasonably practical, the {@code hashCode} method defined
* by class {@code Object} returns distinct integers for distinct objects.
*
* @return a hash code value for this object.
* @apiNote
* The {@link java.util.Objects#hash(Object...) hash} and {@link
* java.util.Objects#hashCode(Object) hashCode} methods of {@link
* java.util.Objects} can be used to help construct simple hash codes.
*
* @see java.lang.Object#equals(java.lang.Object)
* @see java.lang.System#identityHashCode
*/
Expand Down Expand Up @@ -153,6 +157,9 @@ public Object() {}
* method whenever this method is overridden, so as to maintain the
* general contract for the {@code hashCode} method, which states
* that equal objects must have equal hash codes.
* <p>The two-argument {@link java.util.Objects#equals(Object,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend a blank line before to make the paragraph break more obvious.

* Object) Objects.equals} method implements an equivalence relation
* on two possibly-null object references.
*
* @param obj the reference object with which to compare.
* @return {@code true} if this object is the same as the obj
Expand Down Expand Up @@ -229,7 +236,7 @@ public boolean equals(Object obj) {
protected native Object clone() throws CloneNotSupportedException;

/**
* Returns a string representation of the object.
* {@return a string representation of the object}
* @apiNote
* In general, the
* {@code toString} method returns a string that
Expand All @@ -246,12 +253,14 @@ public boolean equals(Object obj) {
* 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>
* {@snippet lang=java :
* getClass().getName() + '@' + Integer.toHexString(hashCode())
* </pre></blockquote>
*
* @return a string representation of the object.
* }
* The {@link java.util.Objects#toIdentityString(Object)
* Objects.toIdentityString} method returns the string for an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That last sentence doesn't feel like it needs to be part of @implSpec, although there's definitely a connection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, a clear connection to what's being described by that @implSpec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has an existing apiNote and implSpec. I suspect Joe meant to add this sentence to the apiNote, not the implSpec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did mean to add the cross-reference to Objects.toIdentityString to the implSpec section since earlier in the implSpec section the expression that is the basis for Objects.toIdentityString is listed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately, is it just me or this sentence could be rephrased to not read like toIdentityString(Object) accepts an object equal to the string (that would ...)?

* object equal to the string that would be returned if neither
* the {@code toString} nor {@code hashCode} methods were
* overridden by the object's class.
*/
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
Expand Down Expand Up @@ -446,16 +455,16 @@ public final void wait(long timeoutMillis) throws InterruptedException {
* below. Among other things, this approach avoids problems that can be caused
* by spurious wakeups.
*
* <pre>{@code
* {@snippet lang=java :
* synchronized (obj) {
* while (<condition does not hold> and <timeout not exceeded>) {
* while ( <condition does not hold and timeout not exceeded> ) {
* long timeoutMillis = ... ; // recompute timeout values
* int nanos = ... ;
* obj.wait(timeoutMillis, nanos);
* }
* ... // Perform action appropriate to condition or timeout
* }
* }</pre>
* }
*
* @param timeoutMillis the maximum time to wait, in milliseconds
* @param nanos additional time, in nanoseconds, in the range 0-999999 inclusive
Expand Down Expand Up @@ -555,15 +564,16 @@ public final void wait(long timeoutMillis, int nanos) throws InterruptedExceptio
* To guard against exceptions prematurely terminating the finalize chain,
* the subclass should use a {@code try-finally} block to ensure
* {@code super.finalize()} is always invoked. For example,
* <pre>{@code @Override
* {@snippet lang="java":
* @Override
* protected void finalize() throws Throwable {
* try {
* ... // cleanup subclass state
* } finally {
* super.finalize();
* }
* }
* }</pre>
* }
*
* @deprecated Finalization is deprecated and subject to removal in a future
* release. The use of finalization can lead to problems with security,
Expand Down