lambda -> method ref: make cast type denotable (IDEA-134217)

This commit is contained in:
Anna Kozlova
2016-01-04 18:08:42 +01:00
parent 2a26241573
commit 01fc1dc40f
3 changed files with 70 additions and 23 deletions

View File

@@ -0,0 +1,22 @@
// "Replace lambda with method reference" "true"
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
class Collectors2 {
static <T> Map<T, Integer> combine(Collection<Map<? extends T, Integer>> pMaps) {
return pMaps.stream()
.map((Function<Map<? extends T, Integer>, Set<? extends Map.Entry<? extends T, Integer>>>) Map::entrySet)
.flatMap(Collection::stream)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(pEntry1, pEntry2) -> pEntry1 + pEntry2,
(Supplier<HashMap<T, Integer>>) HashMap::new
)
);
}
}

View File

@@ -0,0 +1,20 @@
// "Replace lambda with method reference" "true"
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
class Collectors2 {
static <T> Map<T, Integer> combine(Collection<Map<? extends T, Integer>> pMaps) {
return pMaps.stream()
.map((integerMap) -> integerMap.en<caret>trySet())
.flatMap(Collection::stream)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(pEntry1, pEntry2) -> pEntry1 + pEntry2,
(Supplier<HashMap<T, Integer>>) HashMap::new
)
);
}
}