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

(enum) Generate static Enum.fromOrdinal(int ordinal)

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P5
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      A DESCRIPTION OF THE REQUEST :
      When java code needs to interact with legacy systems, other languages etc. The Enum's ordinal value is an obvious choice for transfering between java and the other system. It would be useful if a static method

      MyEnum e = MyEnum.fromOrdinal(int ordinal)

      was generated in my enum class so that i could get the correct enum from the ordinal value.

      JUSTIFICATION :
      This logic must be hand done by checking each enums ordinal value to the other system/languages value. If the number of enums changes in the future, this checking code must be adjusted making it brittle.


      CUSTOMER SUBMITTED WORKAROUND :
      You must loop over all ordinal values comparing as you go. If later on another enum value is added, this loop may need to be adjusted to accomodate this extra item. Using Enum.fromOrdinal would eliminate this programming error.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: