3

MWE:

import java.util.Comparator;
import java.util.TreeMap;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;

public class ShouldCompileInEclipse {

    void doesNotCompileInEclipse() {
        asList("eclipse").stream()
            .collect(groupingBy(
                    this::function,
                    () -> new TreeMap<>(Comparator.reverseOrder()),
                    mapping(this::function, toList())));
    }

    String function(String s) {
        return s;
    }
}

Why the code will not compile under Eclipse?

Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200

The error is:

Cannot infer type arguments for TreeMap<>

It compiles successfully by javac 1.8.0_102

Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51
  • A workaround to compile the code in Eclipse is to add type information to the Comparator.reverseOrder(): Comparator.reverseOrder() – Marcin Kłopotek Nov 22 '16 at 13:19
  • Quite contrived example. Normally, you collect into a map to use it afterwards and then, the type should be inferrable from the target type. – Holger Nov 25 '16 at 10:06
  • I noticed that Neon has problems with generic type recognition already when it came out. Several calls of my personal generic methods do not compile while they have worked before. That's why I still have to stick to Mars.2 where it last worked correctly until this bug is rectified. But it does not seem that this would ever happen... – Arceus Jan 19 '17 at 18:48

0 Answers0