Is there a way to make the following implementation in a type safe manner?
public void myMethod( Map<String, ? extends List<String>> map )
{
map.put("foo", Collections.singletonList("bar");
}
The above implementation doesn't work. It requires a Map<String, ? super List<String>>
to compile the method map.put()
correctly. But myMethod won't accept any subtype of List this way. So, I have to use Map<String, ? extends List<String>>
instead. How can I solve this problem in a type safe manner?