I have seen several questions on this topic, but still can't figure out how to solve this problem. I define and initialize my variable as:
Queue<? extends Map<String, String>> q = new LinkedList<HashMap<String, String>>();
And it compiles. But then:
Map<String, String> m = new HashMap<String, String>();
m.put("foo", "bar");
q.add(m);
reports a compilation error: no suitable method found for add(Map<String,String>)
.
EDIT:
I think this is different to Can't add value to the Java collection with wildcard generic type, because the generics are not nested in that question.
Furthermore, the accepted answer teaches that the specific implementation of a template class can be omited in some declarations. You won't find this teaching on the question marked as duplicate of.