-
Bug
-
Resolution: Unresolved
-
P4
-
10, 11
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Collectors.groupingBy(3 arg) assumes `mapFactory` returns a `Map` where all values can be stored if collector isn't an identity collector. This isn't part of `Map` interface, it's allowed by the language to make maps that only work with certain return values. This isn't documented.
---------- BEGIN SOURCE ----------
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static java.util.Collections.checkedMap;
import static java.util.stream.Collectors.*;
public class Example {
public static void main(String[] args) {
Supplier<Map<String, String>> mapSupplier = () -> checkedMap(new HashMap<>(), String.class, String.class);
Map<String, String> result = Stream.of("a", "b").collect(groupingBy(x -> x, mapSupplier, collectingAndThen(toList(), x -> x.get(0))));
System.out.println(result);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Collectors.groupingBy(3 arg) assumes `mapFactory` returns a `Map` where all values can be stored if collector isn't an identity collector. This isn't part of `Map` interface, it's allowed by the language to make maps that only work with certain return values. This isn't documented.
---------- BEGIN SOURCE ----------
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static java.util.Collections.checkedMap;
import static java.util.stream.Collectors.*;
public class Example {
public static void main(String[] args) {
Supplier<Map<String, String>> mapSupplier = () -> checkedMap(new HashMap<>(), String.class, String.class);
Map<String, String> result = Stream.of("a", "b").collect(groupingBy(x -> x, mapSupplier, collectingAndThen(toList(), x -> x.get(0))));
System.out.println(result);
}
}
---------- END SOURCE ----------
FREQUENCY : always