Why the diamond operator does not work here?

Ulf Zibis Ulf.Zibis at gmx.de
Tue Sep 28 09:23:03 PDT 2010


  Try something like (not sure if it would work):

5         Map<String,? extends List<String>>  map = new HashMap<>();

-Ulf


Am 28.09.2010 14:08, schrieb Weijun Wang:
> 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