Sorry if the question title is confusing. Here is what I mean.
I have a Map<String, ? extends Object> studentDetails = new HashMap<>();
and I want it to hold any random types.
When I put
studentDetails.put("name", "John");
studentDetails.put("friendNames", Arrays.aslist("Kenny","Peter","friend3"));
studentDetails.put("courses", new HashSet<String>());
studentDetails.put("age",18);
Compiler gives me :
required type: capture of ? extends Object, Provided: String
required type: capture of ? extends Object, Provided: ArrayList
required type: capture of ? extends Object, Provided: HashSet
required type: capture of ? extends Object, Provided: Integer
Why is it wrong? Shouldn't ? extends Object
captures any type? If I change it to Map<String, Object>, then it works.
Any help would be appreciated! Thanks!