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

Add support for functional programming to enums.

XMLWordPrintable

    • generic
    • generic

      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 ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: