RFR: 8178355: IdentityHashMap uses identity-based comparison for values everywhere except remove(K,V) and replace(K,V,V)
ExE Boss
duke at openjdk.java.net
Fri Apr 15 13:56:56 UTC 2022
On Fri, 15 Apr 2022 05:58:32 GMT, liach <duke at openjdk.java.net> wrote:
> Explicitly implement `remove` and `replace` in `IdentityHashMap` to compare values by identity. Updated API documentation of these two methods ([Preview](https://cr.openjdk.java.net/~liach/8178355/IdentityHashMap.html#remove(java.lang.Object,java.lang.Object))) to mention such behavior.
test/jdk/java/util/IdentityHashMap/DefaultRemoveReplace.java line 36:
> 34: final String key = "key";
> 35: final String internedValue = "value";
> 36: final String constructedValue = new String(new char[]{'v', 'a', 'l', 'u', 'e'});
Using:
Suggestion:
final String constructedValue = new String(internedValue);
will allow the internal `String.value` array to be shared: <https://github.com/openjdk/jdk/blob/bdf8a2a2050393e91800786f8d5a5d6805f936eb/src/java.base/share/classes/java/lang/String.java#L259-L265>
-------------
PR: https://git.openjdk.java.net/jdk/pull/8259
More information about the core-libs-dev
mailing list