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

consider enhancements to EnumMap and EnumSet

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      The new collections convenience factories (JDK-8048330) make creation of immutable lists, sets, and maps more convenient. This highlights a potential need to enhance EnumMap and EnumSet to bring them into line. There are several issues:

      a) There are six overloads for EnumSet.of(), with one through five arguments, plus a varargs overload. There are no convenience factories for EnumMap. It might make sense to add convenience factories to match the ones in Set and Map. (Note, though, that EnumSet and EnumMap are mutable.)

      b) Calling Set.of(EnumClass.ONE, EnumClass.TWO, EnumClass.THREE) will produce a set of reference type instead of an implementation specialized for enum values.

      c) There are no immutable versions of EnumMap and EnumSet. Note: Guava has Maps.immutableEnumMap() and Sets.immutableEnumSet(), but not any corresponding public types as far as I can see.

      It's not entirely clear what should be done, but there does seem to be room to explore this space.

      See discussion at:

      http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-December/037292.html

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              smarks Stuart Marks
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: