If I have a base class such that
public abstract class XMLSubscription <T extends XMLMessage>
Is it possible to write a method in XMLSubscription that returns a class object of T?
The only possible solution that I came up with is to have each descendant of XMLSubscription have a method like:
public class XMLStatusSubscription extends XMLSubscription<XMLStatusMessage> { public Class <XMLStatusMessage> getExpectedMessageType() { return XMLStatusMessage.class; } }
Unfortunately – and yes, this is due to type erasure – there is no way to return the
Classobject without providing it at runtime somehow.Fortunately this is not usually too difficult. Here’s how I’ve typically done this / seen it done: