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

Stream.iterate() should allow covariant seed and UnaryOperator args

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • core-libs
    • None

      Stream.iterate() currently has two overloads:

          static <T> Stream<T> iterate(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)
          static <T> Stream<T> iterate(T seed, UnaryOperator<T> f)

      This prevents certain combinations of existing values and unary operators from being used. For example:

          UnaryOperator<String> op = s -> s;
          Stream<CharSequence> scs = iterate("", op); // error

      If the methods' declarations were changed like so:

          static <T, S extends T> Stream<T> iterate(S seed, Predicate<? super S> hasNext, UnaryOperator<S> next)
          static <T, S extends T> Stream<T> iterate(S seed, UnaryOperator<S> f)

      Then the above call to iterate() would no longer result in an error.

            Unassigned Unassigned
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: