What I would like to have is something like this:
public abstract Class Content {
private Map<Class<? extends Content>, List<? extends Content>> relations;
}
Content has a bunch of subclasses - A,B,C,D etc...
The most frequent use case is to get all A's:
public List<A> getA() {
return (List<A>)relations.get(A.class);
}
Kind of ok - apart from the ugly cast.
But the real problem is there's nothing stopping me from doing something stupid like:
relations.put(A.class, List<B> myListOfBs);
So a call to getA() above would result in a horrible cast exception. Is there any way I can write it so the compiler would warn me in the above example - and also remove the need for the ugly cast.
Thanks