title: Cannot infer type arguments for hashmap<>
body: <p>I am getting </p>
  
  <pre><code>   Cannot infer type arguments for java.util.HashMap&lt;&gt;
  </code></pre>
  
  <p>for the following code</p>
  
  <pre><code>class Test {
  
      public static void main(String[] args) {
  
          Map&lt;Integer, String&gt; map = new HashMap&lt;&gt;();
          map.put(1, "x");
          map.put(2, "y");
          map.put(3, "x");
          map.put(4, "z");
  
    //the following line has error
          Map&lt;String, ArrayList&lt;Integer&gt;&gt; reverseMap = new java.util.HashMap&lt;&gt;(map.entrySet().stream()
                  .collect(Collectors.groupingBy(Map.Entry::getValue)).values().stream()
                  .collect(Collectors.toMap(item -&gt; item.get(0).getValue(),
                          item -&gt; new ArrayList&lt;&gt;(item.stream().map(Map.Entry::getKey).collect(Collectors.toList())))); 
          System.out.println(reverseMap);
  
      }
  
  }
  </code></pre>
  
  <p>What went wrong and Can anyone Explain me this ?
  I have checked for proper imports and found out that I am importing java.util.hashmap and none other. 
  Still the pesky error is buging me.</p>
  
  <p><a href="https://i.stack.imgur.com/ey3RY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ey3RY.png" alt="The Error Persists"></a></p>