I ran into an issue sooner today when I serialized...
# announcements
l
I ran into an issue sooner today when I serialized a data class that contained an enum, and the hashcode was always different
i
Could you provide a sample which shows that behavior?
l
I'll try to make one. Basically, what I was doing is something like this:
Copy code
var code = 6
code = 31 * code + javaLocalDate.hashCode()
code = 31 * code + MyEnum.Foo.hashCode()   // I didn't overwrite this enum
return code
And I noticed that this would always generate a new hashcode, for the exact same values
I then changed the third line to
code = 31 * code + MyEnum.Foo.toString().hashCode()
And it worked fine from then on
I'll get a concrete example.
i
Or do you mean that you're serializing an enum and after deserializing it in a different process it gets different
hashCode
? In that case it is normal, nothing in hashCode spec implies it should preserve its value in across processes.
l
I think that's closer to what I meant.
That's what doesn't make sense to me
Why chossing this for the default Enum implementation? I get it that it isn't against the specification (although it does seem counter-intuitive), but it makes sense to return the same value always!