Quel est le bon type d'argument de la méthode addAll (..) dans les collections Java? Si je fais quelque chose comme ceci:Les génériques java et la méthode 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);
Je comprends que j'ai besoin d'initialiser les deux variables. Cependant, j'obtiens une erreur de compilation (de l'éclipse):
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'est-ce que je fais mal?
Pouvez-vous modifier pour afficher vos déclarations pour 'currentList' et 'newElements'? – elduff
Je pense que 'newElements' est supposé être 'addAll' J'ai corrigé le code. – Jherico