public class People {
class Family extends People {
}
}
public class Together {
private static Collection<Family> familyList = new ArrayList<Family>();
private static ConcurrentMap<String, Collection<People>> registry = new ConcurrentHashMap<String, Collection<People>>();
static {
registry.put(Family.class.toString(), familyList);
}
}
Error message:
The method put(String, Collection<people>) in the type Map<String,Collection<people>> is not applicable for the arguments (String, Collection<family>)
Why can't I put familyList
into registry
? I figure that since family
extendspeople
that i should be able to place the sub types into the super type registry
.
EDIT: The above is solved. My last part of the question involves a more complicated example using the same names:
public class Together {
private static ConcurrentMap<String, Collection<Family>> familyMap= new ConcurrentHashMap<String, Collection<Family>>();
private static ConcurrentMap<String, ConcurrentMap<String, Collection<People>>> registry2 = new ConcurrentHashMap<String, ConcurrentMap<String, Collection<People>>>();
static {
registry2.put(Family.class.toString(), familyMap);
}
}
(I already tried changing the declaration of registry2
to having ?extends People
Now the error is:
The method put(String, ConcurrentMap<String,Collection<People>>) in the type Map<String,ConcurrentMap<String,Collection<People>>> is not applicable for the arguments (String, ConcurrentMap<String,Collection<Family>>)