I am getting
Cannot infer type arguments for java.util.HashMap<>
for the following code
class Test {
public static void main(String[] args) {
Map<Integer, String> map = new HashMap<>();
map.put(1, "x");
map.put(2, "y");
map.put(3, "x");
map.put(4, "z");
//the following line has error
Map<String, ArrayList<Integer>> reverseMap = new java.util.HashMap<>(map.entrySet().stream()
.collect(Collectors.groupingBy(Map.Entry::getValue)).values().stream()
.collect(Collectors.toMap(item -> item.get(0).getValue(),
item -> new ArrayList<>(item.stream().map(Map.Entry::getKey).collect(Collectors.toList()))));
System.out.println(reverseMap);
}
}
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.