JDK-7184598 : Enum is Comparable but EnumSet is not a SortedSet and EnumMap is not a SortedMap
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2012-07-17
  • Updated: 2019-07-05
  • Resolved: 2019-07-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
While you can construct

    NavigableSet<EnumType> set = new TreeSet<EnumType>();
    NavigableMap<EnumType, Object> map = new TreeMap<EnumType, Object>();

you can't construct

    NavigableSet<EnumType> set = new EnumSet<EnumType>();
    NavigableMap<EnumType, Object> map = new EnumMap<EnumType, Object>();


JUSTIFICATION :
As Enum is Comparable, this implies it has a natural order which you can use in generic sorted collection but not those collection specific to Enums which appears to be inconsistent.

Insert, update and delete on a Tree is O(log n) whereas for an Enum collection its O(1)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
EnumSet supports the functionality which a TreeSet of enum supports
EnumMap supports the functionality which a TreeMap of enum supports.
ACTUAL -
Enum collections are not aware that enum is Comparable.

CUSTOMER SUBMITTED WORKAROUND :
Use a TreeMap and an EnumMap to get O(1) access and a sorted collection.