Having the simple following java code:
Map<Integer,String> map = new HashMap<>();
//map.put("sd","A");
map.put(2,"B");
map.remove(2);
map.remove("A");
I can put only Integer keys (thus commented line cause a compile time error) but I can remove any class Keys (thus last line is valid). Type is checked in put() but not in remove().
Why Map.put method uses the key parameter type and remove method does not?
Wouldn't be helpful the compiler to inform, as it does in put(), that I use Integers as type for keys thus there is no mean trying to remove String keys?