java generics and the addAll method

Posted by neesh on Stack Overflow See other posts from Stack Overflow or by neesh
Published on 2010-04-23T19:59:44Z Indexed on 2010/04/23 20:03 UTC
Read the original article Hit count: 303

What is the correct type of argument to the addAll(..) method in Java collections? If I do something like this:

Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>();
// add some hashmaps to the list..
currentList.addAll(newElements); //currentList is of type: List<? extends Map<String, Object[]>> 

I understand I need to initialize both variables. However, I get a compilation error (from 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[]>>)

what am I doing wrong?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics