Here are 2 code snippets, which are supposed to return the same result, as I used HashMap in map factory.
But the second code snippet doesn't compile in IntelliJ. Both codes work fine in Eclipse.
System.out.println method required something where it can call toString, but in IntelliJ I get this weird error, Why ?
Compileable code (both Eclipse & IntelliJ):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
Collectors.counting())));
Erroneous Code (works in Eclipse but fails only in IntelliJ):
System.out.println(Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(
Function.identity(),
HashMap::new,
Collectors.counting())));
The error for second snippet in IntelliJ
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