I have a map like the one below
final Map<String, ? extends Object> map
Can anyone tell me why this operation is not possible..?
productMap.put("min", String.valueof(34));
What should be the turnaround…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ve told the compiler that the map values will be some specific subtype of Object. ? could be anything — you could do:
So String might be invalid.
You probably want the simpler Map which does allow any value.
Or you can “cheat” and do a cast which hides the generic type:
But that trick is not best practice & to be used sparingly if at all.