JDK-8174804 : Add support for functional programming to enums.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-02-12
  • Updated: 2017-05-11
  • Resolved: 2017-05-11
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
1. Add a stream() method to java.lang.Enum. This will simplify dealing with enum values, instead of calling values() which returns an array.

2. Add  an overload of method of() to EnumSet that uses a predicate to determine the elements in the set;
    public static <E extends Enum<E>> Set<E> of(final Predicate<E> aPredicate).

JUSTIFICATION :
Not necessary but would simplify functional programming using enums:

1. Enum.stream()
Currently have to obtain a stream indirectly, e.g:
(a) call values() to get an array of enum values, convert the array to a List, call stream() on the List.
or
(b) call EnumSet.allOf(elementType) to get an EnumSet of the values and call stream on the EnumSet.

2. EnumSet.of(Predicate<E>)
The current of() methods select by element identity. EnumSet.of(Predicate<E>) would select elements  by their properties.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Not applicable
ACTUAL -
Not applicable

---------- BEGIN SOURCE ----------
Not applicable
---------- END SOURCE ----------