【发布时间】:2015-04-22 09:48:04
【问题描述】:
考虑这个转换示例(请参阅关于应该发生什么的详细描述here):
Map<String, Integer> transform(Map<Integer, List<String>> old) {
old.entrySet().stream()
.flatMap(entry -> entry.getValue().stream()
.map(letter -> letter.toLowerCase())
.map(lowerCaseLetter -> new SimpleEntry<String, Integer>(lowerCaseLetter, entry.getKey())))
// at this point, the type is Stream<Object>, not Stream<SimpleEntry<String,Integer>>
.collect(Collectors.toMap());
}
为什么关于特定类型的信息会在这里丢失,我该如何解决这个问题?
【问题讨论】:
-
对我来说工作得很好。尝试使用 javac。你在用 Eclipse 吗?
-
是的,我是... javac 也为我工作。猜猜这是eclipse中的一个错误..
-
是的,Eclipse 在其自己的编译器(尤其是在类型推断方面)和 java 8 特性方面仍然存在问题。你可以向 Eclipse 开发团队提交一个 bug,或者切换到 IntelliJ(它使用 javac,这是我在 Java 8 之后切换到它的主要原因之一......)
-
如果您将其添加为答案,我会接受。如果这是一个已知错误,也许您可以提供该问题的链接?
标签: java lambda functional-programming