Even though a List<Number>
is a List<? extends Number>
, a HashMap<String, List<Number>>
is not a Map<String, List<? extends Number>
, because Java's generics are invariant. This is the same thing that makes a List<Dog>
not assignable to a List<Animal>
, even if Dog
extends Animal
. Here, List<Number>
plays the part of the Dog
and List<? extends Number>
plays the part of the Animal
.
List<Number>
can't match List<? extends Number>
when used as a type parameter.
You can get (2) to compile by introducing a wildcard: Change
Map <String,List<? extends Number>> mp = new HashMap<String,List<Number>>();
to
Map <String, ? extends List<? extends Number>> mp = new HashMap<String,List<Number>>();