I do not understand the general boundies pattern . ussage. Could you explain why it processListworks very well and processMapfails with a compilation error in the following example? How to change the signature processMapso that it works both with Map<String, List<String>>andMap<String, List<Object>>
public void processList(List<? extends Object> list) {
}
public void processMap(Map<String, List<? extends Object>> map) {
}
public void f() {
List<String> list = new ArrayList<>();
Map<String, List<String>> map = new HashMap<>();
processList(list);
processMap(map);
}
When moving the generic type definition from the type of the method argument to the paramether method did the trick
public void processMap(Map<String, List<? extends Object>> map)
public <T extends Object> void processMap(Map<String, List<T>> map)
Now I would like to know the difference between the two. Moved to another thread .
source
share