mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8280168: Add Objects.toIdentityString
Reviewed-by: alanb, mchung, rriggs, smarks
This commit is contained in:
parent
f4575e4052
commit
cbe8395ace
3 changed files with 60 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2022, 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
|
||||
|
@ -164,6 +164,30 @@ public final class Objects {
|
|||
return (o != null) ? o.toString() : nullDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string equivalent to the string returned by {@code
|
||||
* Object.toString} if that method and {@code hashCode} are not
|
||||
* overridden}
|
||||
*
|
||||
* @implNote
|
||||
* This method constructs a string for an object without calling
|
||||
* any overridable methods of the object.
|
||||
*
|
||||
* @implSpec
|
||||
* The method returns a string equivalent to:<br>
|
||||
* {@code o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o))}
|
||||
*
|
||||
* @param o an object
|
||||
* @throws NullPointerException if the argument is null
|
||||
* @see Object#toString
|
||||
* @see System#identityHashCode(Object)
|
||||
* @since 19
|
||||
*/
|
||||
public static String toIdentityString(Object o) {
|
||||
requireNonNull(o);
|
||||
return o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0 if the arguments are identical and {@code
|
||||
* c.compare(a, b)} otherwise.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue