On 8/9/2022 11:56 PM, Peter Levart wrote:
On Sun, 7 Aug 2022 08:14:58 GMT, Alan Bateman <al...@openjdk.org> wrote:

Sorry for joining late. I noticed that modsHashCode is a private method and it 
takes Iterable as a parameter. But everywhere it is called, a Set is passed to 
it. So why not just calling the set.hashCode() and be done with it? It may be 
even more optimal in some cases.
There's a lot going on here as the hash code is generated at link time and we 
also want it to be reproducible across builds. We also had a CDS bug with the 
the way that Enum objects were archived - Ioi has fixed that in JDK 19 so we 
have one less thing to be concerned about now.
Ah, I see. Enum.hashCode() is identity hash code. I have been beaten by that in 
the past and apparently this is a sore point for many. I wonder if it could be 
changed. Is unstable hashCode (accross JVM instances) a feature here or just 
unfortunate implementation detail?

We've gotten a few issues filed about Enum.hashCode() over the years, one more recent one is

    JDK-8050217: Enum.hashCode() should return ordinal value for the enum, for better consistency

Current thinking per that issue is the present behavior is more of a feature than a bug.

-Joe

Reply via email to