Skip to content

Commit 0e4fde3

Browse files
committed
8310453: Update javadoc of java.lang.Object
Reviewed-by: rriggs, alanb
1 parent 230bcb7 commit 0e4fde3

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,7 @@ public Object() {}
6767
public final native Class<?> getClass();
6868

6969
/**
70-
* Returns a hash code value for the object. This method is
70+
* {@return a hash code value for this object} This method is
7171
* supported for the benefit of hash tables such as those provided by
7272
* {@link java.util.HashMap}.
7373
* <p>
@@ -95,7 +95,11 @@ public Object() {}
9595
* As far as is reasonably practical, the {@code hashCode} method defined
9696
* by class {@code Object} returns distinct integers for distinct objects.
9797
*
98-
* @return a hash code value for this object.
98+
* @apiNote
99+
* The {@link java.util.Objects#hash(Object...) hash} and {@link
100+
* java.util.Objects#hashCode(Object) hashCode} methods of {@link
101+
* java.util.Objects} can be used to help construct simple hash codes.
102+
*
99103
* @see java.lang.Object#equals(java.lang.Object)
100104
* @see java.lang.System#identityHashCode
101105
*/
@@ -153,6 +157,9 @@ public Object() {}
153157
* method whenever this method is overridden, so as to maintain the
154158
* general contract for the {@code hashCode} method, which states
155159
* that equal objects must have equal hash codes.
160+
* <p>The two-argument {@link java.util.Objects#equals(Object,
161+
* Object) Objects.equals} method implements an equivalence relation
162+
* on two possibly-null object references.
156163
*
157164
* @param obj the reference object with which to compare.
158165
* @return {@code true} if this object is the same as the obj
@@ -229,7 +236,7 @@ public boolean equals(Object obj) {
229236
protected native Object clone() throws CloneNotSupportedException;
230237

231238
/**
232-
* Returns a string representation of the object.
239+
* {@return a string representation of the object}
233240
* @apiNote
234241
* In general, the
235242
* {@code toString} method returns a string that
@@ -246,12 +253,14 @@ public boolean equals(Object obj) {
246253
* the unsigned hexadecimal representation of the hash code of the
247254
* object. In other words, this method returns a string equal to the
248255
* value of:
249-
* <blockquote>
250-
* <pre>
256+
* {@snippet lang=java :
251257
* getClass().getName() + '@' + Integer.toHexString(hashCode())
252-
* </pre></blockquote>
253-
*
254-
* @return a string representation of the object.
258+
* }
259+
* The {@link java.util.Objects#toIdentityString(Object)
260+
* Objects.toIdentityString} method returns the string for an
261+
* object equal to the string that would be returned if neither
262+
* the {@code toString} nor {@code hashCode} methods were
263+
* overridden by the object's class.
255264
*/
256265
public String toString() {
257266
return getClass().getName() + "@" + Integer.toHexString(hashCode());
@@ -446,16 +455,16 @@ public final void wait(long timeoutMillis) throws InterruptedException {
446455
* below. Among other things, this approach avoids problems that can be caused
447456
* by spurious wakeups.
448457
*
449-
* <pre>{@code
458+
* {@snippet lang=java :
450459
* synchronized (obj) {
451-
* while (<condition does not hold> and <timeout not exceeded>) {
460+
* while ( <condition does not hold and timeout not exceeded> ) {
452461
* long timeoutMillis = ... ; // recompute timeout values
453462
* int nanos = ... ;
454463
* obj.wait(timeoutMillis, nanos);
455464
* }
456465
* ... // Perform action appropriate to condition or timeout
457466
* }
458-
* }</pre>
467+
* }
459468
*
460469
* @param timeoutMillis the maximum time to wait, in milliseconds
461470
* @param nanos additional time, in nanoseconds, in the range 0-999999 inclusive
@@ -555,15 +564,16 @@ public final void wait(long timeoutMillis, int nanos) throws InterruptedExceptio
555564
* To guard against exceptions prematurely terminating the finalize chain,
556565
* the subclass should use a {@code try-finally} block to ensure
557566
* {@code super.finalize()} is always invoked. For example,
558-
* <pre>{@code @Override
567+
* {@snippet lang="java":
568+
* @Override
559569
* protected void finalize() throws Throwable {
560570
* try {
561571
* ... // cleanup subclass state
562572
* } finally {
563573
* super.finalize();
564574
* }
565575
* }
566-
* }</pre>
576+
* }
567577
*
568578
* @deprecated Finalization is deprecated and subject to removal in a future
569579
* release. The use of finalization can lead to problems with security,

0 commit comments

Comments
 (0)