What is the reason behind Enum.hashCode()?

后端 未结 7 683
醉酒成梦
醉酒成梦 2020-12-01 02:32

The method hashCode() in class Enum is final and defined as super.hashCode(), which means it returns a number based on the address of the instance, which is a random number

7条回答
  •  猫巷女王i
    2020-12-01 03:10

    As long as we can't send an enum object1 to a different JVM I see no reason for putting such a requirements on enums (and objects in general)


    1 I thought it was clear enough - an object is an instance of a class. A serialized object is a sequence of bytes, usually stored in a byte array. I was talking about an object.

提交回复
热议问题