Why the diamond operator does not work here?

Weijun Wang weijun.wang at oracle.com
Tue Sep 28 05:08:03 PDT 2010


Compiling this program

1 import java.util.*;
2
3 class A3 {
4     public static void main(String[] args) {
5         Map<String,List<String>> map = new HashMap<>();
6         map.put("x", new ArrayList<>());   // compile error!
7     }
8 }

results in

A3.java:6: method put in interface Map<K,V> cannot be applied to given types
         map.put("x", new ArrayList<>());
            ^
   required: String,List<String>
   found: String,ArrayList<Object>
   where K,V are type-variables:
     K extends Object declared in interface Map
     V extends Object declared in interface Map
1 error

Thanks
Max



More information about the coin-dev mailing list