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

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

    XMLWordPrintable

Details

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

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: