8132097: Stream.generate should use a covariant Supplier as parameter
Reviewed-by: forax, martin
--- 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;
}