RFR: 8306075: Micro-optimize Enum.hashCode [v3]
Chen Liang
liach at openjdk.org
Mon Apr 17 13:57:43 UTC 2023
On Mon, 17 Apr 2023 13:45:05 GMT, Andrei Pangin <apangin at openjdk.org> wrote:
>> olivergillespie has refreshed the contents of this pull request, and previous commits have been removed. Incremental views are not available. The pull request now contains one commit:
>>
>> 8306075: Micro-optimize Enum.hashCode
>
> src/java.base/share/classes/java/lang/Enum.java line 181:
>
>> 179: */
>> 180: @Stable
>> 181: private int hash;
>
> Should not we hide the field from reflection?
>
> I understand this is an implementation detail, however, it makes a big difference that you add a private field to the *public* class that is *meant* to be inherited by user classes. Although I'm not aware of a particular example, this can be a breaking change for user code that does introspection on enums.
How is this a big difference? It's only discovered by getDeclaredFields. This can only be modified if users break jdk internal encapsulation in command line, which means they can change everything else.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13491#discussion_r1168738513
More information about the core-libs-dev
mailing list