Java 8 Lambda,过滤器HashMap,无法解析方法
我对Java 8的新功能有点陌生。我正在学习如何按条目过滤地图。我已经查看了本教程和这篇文章,以解决我的问题,但我无法解决。
@Test
public void testSomething() throws Exception {
HashMap<String, Integer> map = new HashMap<>();
map.put("1", 1);
map.put("2", 2);
map = map.entrySet()
.parallelStream()
.filter(e -> e.getValue()>1)
.collect(Collectors.toMap(e->e.getKey(), e->e.getValue()));
}
但是,我的IDE(IntelliJ)说“无法解析方法'getKey()'”,因此无法编译:
这也没有帮助:
任何人都可以帮我解决这个问题吗?谢谢。