RFR: 8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBootstraps$TypePairs [v3]

Claes Redestad redestad at openjdk.org
Mon Apr 22 08:57:45 UTC 2024


On Sat, 20 Apr 2024 07:39:53 GMT, Chen Liang <liach at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 685:
>> 
>>> 683:     record TypePairs(Class<?> from, Class<?> to) {
>>> 684: 
>>> 685:         private static final Map<TypePairs, String> typePairToName = initialize();
>> 
>> If `TypePairs.typePairToName` is never modified after initialisation, then it should probably be made immutable:
>> Suggestion:
>> 
>>         private static final Map<TypePairs, String> typePairToName = Map.copyOf(initialize());
>
> If you really think about it, the `initialize` method itself is somewhat problematic, as it's initializing with byte/short/char on the left, all of which are already converted to int in the of() factory. This should be done in a separate issue.

Yes, the "redirected" mappings can simply be removed in the current implementation. 

Using `Map.copyOf` should be ok to nail down the read-only intent.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18865#discussion_r1574385797


More information about the core-libs-dev mailing list