Please help me! There i have two pieces of code:
1:
public static <K, V> void addElement(Map<K, Collection<V>> map) { }
public static void main(String[] args) {
Map<String, List<Integer>> map = new HashMap<String, List<Integer>>();
addElement(map);
}
2:
public static <V> void addElement(Collection<V> collection) { }
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
addElement(list);
}
The code of pieces 1 cannot be compiled!when i try to compiled, jvm tell me:'Map<String, List> cannot be converted to Map<K, Collection>'
Some of my friends tell me that the list unable upcast to collectoin, but the code of pieces 2 can be compiled!
so What is the reason that the first code cannot be compiled?