【发布时间】:2020-01-12 04:09:29
【问题描述】:
这里有 2 个代码 sn-ps,它们应该返回相同的结果,因为我在 map factory 中使用了 HashMap。
但是第二个代码 sn-p 不能在 IntelliJ 中编译。两种代码在 Eclipse 中都能正常工作。
System.out.println 方法需要一些可以调用toString 的东西,但是在 IntelliJ 中我得到了这个奇怪的错误,为什么?
可编译代码(Eclipse 和 IntelliJ):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
Collectors.counting())));
错误代码(在 Eclipse 中有效,但仅在 IntelliJ 中失败):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
HashMap::new,
Collectors.counting())));
IntelliJ中第二个sn-p的错误
Required type: String
Provided: Map
<java.lang.String,java.lang.Long> no instance(s) of type variable(s) K, V exist so that HashMap<K, V> conforms to String
【问题讨论】:
-
这段代码对我来说很好,没有错误。
-
感谢您指出...在您发表评论后,我在 eclipse 中尝试了相同的代码并且它有效。但在 IntelliJ 中,它甚至无法编译。我将重新提出我的问题,问为什么它在 IntelliJ 中不起作用但在 eclipse 中起作用。
-
请发布一个完整的最小示例来重现该问题,以及您从编译器获得的准确和完整的错误。
标签: eclipse intellij-idea java-8 intellij-14