Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GroupingByStreamTest {
- class Double<A, B> {
- A a;
- B b;
- public Double(A a, B b) {
- this.a = a;
- this.b = b;
- }
- }
- class Triple<A, B, C> extends Double<A, B> {
- C c;
- public Triple(A a, B b, C c) {
- super(a, b);
- this.c = c;
- }
- }
- @Test
- public void shouldGroupToMap() throws Exception {
- List<Triple<String, String, String>> listOfTriples = asList(
- new Triple<>("a-1", "b-1", "c-1"),
- new Triple<>("a-1", "b-2", "c-2"),
- new Triple<>("a-1", "b-3", "c-3"),
- new Triple<>("a-2", "b-4", "c-4"),
- new Triple<>("a-2", "b-5", "c-5"));
- // This code below compiles and executes OK. If I put a breakpoint
- // in my EDI I can even see the expected Map being created. However
- // if you uncomment the line below and comment the one after it the
- // code will no longer compile.
- // Map<String, List<Double<String, String>>> myMap =
- Map<Object, List<Double<Object, Object>>> myMap =
- listOfTriples.stream().collect(groupingBy(t -> t.a,
- mapping((Triple t) -> new Double<>(t.b, t.c),toList())));
- assertEquals(2, myMap.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement