-
Enhancement
-
Resolution: Unresolved
-
P3
-
None
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().
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().
- duplicates
-
JDK-8174804 Add support for functional programming to enums.
-
- Closed
-
- relates to
-
JDK-8170351 JEP 301: Enhanced Enums
-
- Closed
-
-
JDK-6234270 Class Enum needs a function like Enum<E> getEnumFor(int)
-
- Closed
-
-
JDK-6548438 (enum) java.lang.Enum should have a values(Class<T>) method.
-
- Closed
-
-
JDK-5034509 (enum) Add a function to query if enum name is a valid enum constant name
-
- Closed
-
-
JDK-8261007 Frozen Arrays (Preview)
-
- Draft
-
(1 relates to)