Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8050217

Enum.hashCode() should return ordinal value for the enum, for better consistency

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 9
    • core-libs
    • generic

      A DESCRIPTION OF THE REQUEST :
      I discovered, that java.lang.Enum.hashCode() returns default hashCode value.

      It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.

      JUSTIFICATION :
      It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Enum.hashCode() should return Enum.ordinal() value
      ACTUAL -
      Enum.hashCode() returns default Object.hashCode() value

            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: