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