For example why doesn't the following work?
Map<String, ? extends Object> table = new HashMap<>();
table.put("K", "V"); //Error V cannot be applied to ? extends String.
However String must extend Object, why does the above throw compiler error?
The IntelliJ error I get is
Wrong 2nd Argument Type. Found 'java.lang.String'required: '? extends java.lang.Object'
However the following works:
Map<String, ? super Object> table = new HashMap<>();
table.put("K", "V"); //Error V cannot be applied to ? extends String.
Now the above is truly weird. How can a lowerbound work on Object class?
I mean doesn't
? super Object
mean an "Unknown that is superclass of Object"?
AFAIK Object is at root of Java class hierarchy.