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

need API to get enum's values without creating a new array

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • None
    • core-libs

      Every enum type provides a values() method that returns an array of the enum constants. Since arrays are mutable, the returned array must be a freshly created copy of the internal array.

      It would be nice to have an API that returned an object that represented the enum constants, but avoided having to make a copy of the array just for defensive purposes. For some enum type E this could be something like Stream<E> or perhaps List<E>, with the latter having properties of being random-access and immutable.

      Something to consider is having two "flavors" or this method, one on the enum type itself, and another on java.lang.Enum or java.lang.Class that would provide the values for an enum given its class. This is similar to the situation with values(), which occurs directly on the enum type, and which has an equivalent java.lang.Class.getEnumConstants().

            psandoz Paul Sandoz
            smarks Stuart Marks
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: