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

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

    XMLWordPrintable

Details

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

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: