Why is the below code giving a compile time error.
Map<String,? extends Object> inputMap =
new HashMap<String, ? extends Object>();
The compile time error.
Cannot instantiate the type
HashMap<String,? extends Object>
I want a map with String as key and which takes any object as value
? does not mean "takes any object". It means "take a specific type of object, that happens to be unknown", which doesn't make sense when actually creating a container.
Try this instead:
Map<String,Object> inputMap = new HashMap<String,Object>();
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