This can be explained better with small example, let's take a method with generic argument of Map
public static void m1(Map<? extends Number, ? extends Object> test2) {
}
Now you can create Map
objects with key as Number
or it's child classes and value as Object
or it child classes and call that method
Map<Integer, String> map1 = new HashMap<Integer, String>();
m1(map1);
Map<Double, String> map2 = new HashMap<Double, String>();
m1(map2);
Map<Number, StringBuffer> map3 = new HashMap<Number, StringBuffer>();
m1(map3);
Map<Integer, StringBuilder> map4 = new HashMap<Integer, StringBuilder>();
m1(map4);
? extends Number
doesn't mean map can contains Number
or it's child object, it means either you can create Map
with key as Number
or it's child's. which is the same for value also ? extends Object
either Object
or it's child's