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

Wipe out enum ordinal() method usage

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:
    • CPU:
      generic
    • OS:
      generic

      Description

      Justification obtained from the swing-dev alias in the review-request for 8145547 :

      javadoc for ordinal:
      "Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures, such as EnumSet and EnumMap."

      Quote from the internet:
      "This is not recommended to use ordinal() (Effective Java, Item 31) as it relies on the order of the enum values in client's code determine the ordinal, and any change could lead to bad values being mapped.

      Instead, it would be better to have users implement a method that would return a unique ID for an enum value. For instance, with an Identifiable interface that has a unique method id(), that the user would have to implement for every enum value."

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ssadetsky Semyon Sadetsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: