8132097: Stream.generate should use a covariant Supplier as parameter
authorpsandoz
Wed, 16 Nov 2016 14:26:12 -0800
changeset 42156 7ccdf3aa0f8c
parent 42155 c9b28ab5297b
child 42157 3e87fa9d8226
8132097: Stream.generate should use a covariant Supplier as parameter Reviewed-by: forax, martin
jdk/src/java.base/share/classes/java/util/stream/Stream.java
jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java
--- a/jdk/src/java.base/share/classes/java/util/stream/Stream.java	Wed Nov 16 12:50:29 2016 -0800
+++ b/jdk/src/java.base/share/classes/java/util/stream/Stream.java	Wed Nov 16 14:26:12 2016 -0800
@@ -1327,7 +1327,7 @@
      * @param s the {@code Supplier} of generated elements
      * @return a new infinite sequential unordered {@code Stream}
      */
-    public static<T> Stream<T> generate(Supplier<T> s) {
+    public static<T> Stream<T> generate(Supplier<? extends T> s) {
         Objects.requireNonNull(s);
         return StreamSupport.stream(
                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s), false);
--- a/jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java	Wed Nov 16 12:50:29 2016 -0800
+++ b/jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java	Wed Nov 16 14:26:12 2016 -0800
@@ -1346,9 +1346,9 @@
         }
 
         static final class OfRef<T> extends InfiniteSupplyingSpliterator<T> {
-            final Supplier<T> s;
+            final Supplier<? extends T> s;
 
-            OfRef(long size, Supplier<T> s) {
+            OfRef(long size, Supplier<? extends T> s) {
                 super(size);
                 this.s = s;
             }