¿Cuál es el tipo correcto de argumento para el método addAll (..) en las colecciones de Java? Si hago algo como esto:java generics y el método addAll
List<? extends Map<String, Object[]>> currentList = new ArrayList<Map<String, Object[]>>();
Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>();
// add some hashmaps to the list..
currentList.addAll(addAll);
Entiendo que necesito inicializar ambas variables. Sin embargo, aparece un error de compilación (del eclipse):
Multiple markers at this line
- The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments (List<capture#2-of ? extends
Map<String,Object[]>>)
- The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments
(Collection<HashMap<String,Object[]>>)
¿Qué estoy haciendo mal?
¿Puede editar para mostrar sus declaraciones tanto para 'currentList' como para 'newElements'? – elduff
Creo que se supone que 'newElements' es 'addAll'. He reparado el código. – Jherico