Generics and inheritance: need a complex Map instance
问题 public abstract class Mother { } public class Daughter extends Mother { } public class Son extends Mother { } I need a Map which keys are one of Daughter or Son classes, and which values are lists of objects of one of those two classes, respectively . For example: /* 1. */ map.put(Daughter.class, new ArrayList<Daughter>()); // should compile /* 2. */ map.put(Son.class, new ArrayList<Son>()); // should compile /* 3. */ map.put(Daughter.class, new ArrayList<Son>()); // should not compile /* 4.