when I declare a Map or Map <Object,Object> I can put anything in this Map
Map map = new HashMap();
map.put("");
but if I declare it as Map <?,?> I can put nothing in it
Map<?,?> map = new HashMap();
map.put("");
it will goes wrong why ?
Map<?,?> map = new HashMap<Integer, Integer>(); // compiles just fine!
? represents some fixed but unknown type. You can't put "" in a Map<Integer, Integer>, and a Map<?, ?> is allowed to be any type of Map, including a Map<Integer, Integer>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With