Need to cast an object to unbounded wildcard....but how in my case?

626 views Asked by At
public myConstuctor(Map<String, ?> myMap) {

    if (myMap.containsKey(MY_KEY)) {            

        myMap.put(MY_KEY, someObject);
    }

    someMemberVariable = new someClass(myMap);  
}

I am not able to put an object in the map due to the unbounded wildcard. I am not familiar with wildcard. What makes it difficult (for me..) is I am not able to change the constructor's input type (i.e. myMap) but I need to put an object in the map.

Will someone help..? Thanks in advance!

1

There are 1 answers

3
irreputable On

if you believe the type of someObject is compatible with myMap,

((Map)myMap).put(k, v);