当从流中收集时,我无法看到Entry getKey()和getValue()方法,因为Eclipse只提供Object方法,尽管所有的编译都是正常的。
someMap.entrySet().stream()
.filter( entry -> entry.getKey().isConsumed() || entry.getKey().getSurvivalCount() > 0)
// this compiles but auto-completion only offers object methods
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));是这个Eclipse还是我遗漏了什么?
我使用的是:版本: Mars.1版本(4.5.1)
用于可视化的图像:

发布于 2016-05-19 15:07:43
当我将谓词指定为匿名内部类时,Eclipse很高兴:
Predicate<Entry<String, Integer>> predicate = new Predicate<Entry<String, Integer>>() {
public boolean test(Entry<String, Integer> entry) {
return entry.getKey() == null || entry.getKey().length() > 6;
}
};
// ...
someMap.entrySet().stream().filter(predicate)然而,蓝宝石是有问题的。以前有其他的eclipse bug,例如它甚至没有编译,比如这或这 one。
因此,看起来您发现了一个具有lambda和代码完成的bug。
发布于 2016-05-19 15:14:50
我使用的是版本: Mars.2版本(4.5.2),构建id: 20160218-0600,我也遇到了与您相同的问题。
它看起来像一个bug,因为它将entry变量识别为Entry类型的对象。不过,我在Eclipse 错误列表中找不到这个bug。
https://stackoverflow.com/questions/37326810
复制相似问题