public abstract class Mother {
}
public class Daughter extends Mother {
}
public class Son extends Mother {
}
I don't think it's possible to encode this in the type, I'd do it with a custom class
class ClassMap<T> {
private Map<Class<? extends T>, List<? extends T>> backingMap = new HashMap<>();
public <E extends T> void put(Class<E> cls, List<E> value) {
backingMap.put(cls, value);
}
@SuppressWarnings("unchecked")
public <E extends T> List<E> get(Class<E> cls) {
return (List<E>)backingMap.get(cls);
}
}
It's safe to suppress warnings here as long as you don't leak the backingMap
reference outside this class.
Assuming you're looking for a single map, no this is not possible.