StreamToLoop: fixed method references unwrap when functional interface type parameter is captured wildcard with upper bound

This commit is contained in:
Tagir Valeev
2017-01-20 17:51:09 +07:00
parent ef5e6d4d3d
commit 305c101ca6
3 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
import java.util.OptionalInt;
public class Main {
interface Index {
int asInteger();
}
interface IndexSet<S extends Index> {
List<S> asList();
}
public static OptionalInt min(IndexSet<?> set) {
boolean seen = false;
int best = 0;
for (Index index : set.asList()) {
int i = index.asInteger();
if (!seen || i < best) {
seen = true;
best = i;
}
}
return seen ? OptionalInt.of(best) : OptionalInt.empty();
}
}

View File

@@ -0,0 +1,20 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
import java.util.OptionalInt;
public class Main {
interface Index {
int asInteger();
}
interface IndexSet<S extends Index> {
List<S> asList();
}
public static OptionalInt min(IndexSet<?> set) {
return set.asList()
.<caret>stream()
.mapToInt(Index::asInteger)
.min();
}
}