The class TrainingData has an attribute intent which can be of any of the subtypes of class Intent. I am trying to use Java Generics to enforce that the generic type T can only be a sub-class of Intent. How can I do that?
public class TrainingData<T> extends Data { private T intent; private String id; public TrainingData (UserCommand userCommand, T intent) { super(userCommand); this.intent = intent; } public Klass getKlass() { return intent.getKlass(); // <-- THIS WORKS ONLY IF T extends from Intent } public Intent getIntent() { return intent; } public void setIntent(Intent intent) { this.intent = intent; } @Override public String toString() { return "TrainingData [intent=" + intent + ", id: " + id + "]"; } }