简体   繁体   English

需要将对象强制转换为无界通配符...但是在我的情况下呢?

[英]Need to cast an object to unbounded wildcard…but how in my case?

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 (ie myMap) but I need to put an object in the map. (对我来说。。。。。。。。。。。。。。。。。。。)。。。。。。。。。。。。。。。。

Will someone help..? 会有人帮忙吗? Thanks in advance! 提前致谢!

如果您认为someObject的类型与myMap兼容,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM