0
我已经看到了有关此主题的几个问题,但仍无法弄清楚如何解决此问题。我定义和初始化我的变量为:嵌套的泛型和通配符
Queue<? extends Map<String, String>> q = new LinkedList<HashMap<String, String>>();
然后编译。但是:
Map<String, String> m = new HashMap<String, String>();
m.put("foo", "bar");
q.add(m);
报告编译错误:no suitable method found for add(Map<String,String>)
。
编辑:
我认为这是Can't add value to the Java collection with wildcard generic type不同,因为仿制药没有嵌套在该问题。
此外,接受的答案教导了模板类的具体实现可以在一些声明中省略。你不会在标记为重复的问题上找到这个教导。
真棒!当然!我不知道现在可以推迟宣布实施地图。谢谢。 – clapas 2014-10-05 13:50:40