JDK-6515173 : (enum) Generate static Enum.fromOrdinal(int ordinal)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-01-19
  • Updated: 2011-02-16
  • Resolved: 2010-06-10
Related Reports
Duplicate :  
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.

Comments
EVALUATION Closing as duplicate of 6436941.
10-06-2010