Skip to main content
added 6 characters in body; edited title
Source Link
howlger
  • 35k
  • 11
  • 73
  • 112

Why same code works in eclipseEclipse but doesn't even compile in intelliJIntelliJ

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 

Why same code works in eclipse but doesn't even compile in intelliJ

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 

Why same code works in Eclipse but doesn't even compile in IntelliJ

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 
deleted 36 characters in body; edited tags; edited title
Source Link

What is the difference between 3 arg and 2 arg Collectors.groupingBy Why same code works in eclipse but doesn't even compile in intelliJ

I understand that, this is something related to type inference, But can someone explain this.

FollowingHere are 2 code snippets, which are supposed to return the same result, as I used Hashmap in mapFactorymap factory,. But the second onecode snippet doesn't compile in IntelliJ, Both codes work fine in eclipse. Because the  

System.out.println method required something of type String, and erroneous code collector is not returning a map where toStringit can be called. Whycall 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 in thefor second snippet isin 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 

What is the difference between 3 arg and 2 arg Collectors.groupingBy

I understand that, this is something related to type inference, But can someone explain this.

Following 2 code snippets supposed to return same result, as I used Hashmap in mapFactory, But the second one doesn't compile. Because the System.out.println method required something of type String, and erroneous code collector is not returning a map where toString can be called. Why ?

Compileable Code

 System.out.println(Arrays.stream(str.split(" ")) .collect(Collectors.groupingBy( Function.identity(), Collectors.counting()))); 

Erroneous Code

 System.out.println(Arrays.stream(str.split(" ")) .collect(Collectors.groupingBy( Function.identity(), HashMap::new, Collectors.counting()))); 

The error in the second snippet is

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 

Why same code works in eclipse but doesn't even compile in intelliJ

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 
Source Link

What is the difference between 3 arg and 2 arg Collectors.groupingBy

I understand that, this is something related to type inference, But can someone explain this.

Following 2 code snippets supposed to return same result, as I used Hashmap in mapFactory, But the second one doesn't compile. Because the System.out.println method required something of type String, and erroneous code collector is not returning a map where toString can be called. Why ?

Compileable Code

 System.out.println(Arrays.stream(str.split(" ")) .collect(Collectors.groupingBy( Function.identity(), Collectors.counting()))); 

Erroneous Code

 System.out.println(Arrays.stream(str.split(" ")) .collect(Collectors.groupingBy( Function.identity(), HashMap::new, Collectors.counting()))); 

The error in the second snippet is

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