Eclipse Neon.1 generics compilation error: cannot infer type arguments

萝らか妹 提交于 2019-12-21 21:15:31

问题


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

来源:https://stackoverflow.com/questions/40740223/eclipse-neon-1-generics-compilation-error-cannot-infer-type-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!