java - Generics with Inheritance -
the class trainingdata
has attribute intent
can of of subtypes of class intent
. trying utilize java generics enforce generic type t
can sub-class of intent
. how can that?
public class trainingdata<t> extends info { private t intent; private string id; public trainingdata (usercommand usercommand, t intent) { super(usercommand); this.intent = intent; } public klass getklass() { homecoming intent.getklass(); // <-- works if t extends intent } public intent getintent() { homecoming intent; } public void setintent(intent intent) { this.intent = intent; } @override public string tostring() { homecoming "trainingdata [intent=" + intent + ", id: " + id + "]"; } }
the class trainingdata has attribute intent can of of subtypes of class intent.
try t extends intent
means class extends intent accepted.
public class trainingdata<t extends intent> extends info {...}
read more java tutorial bounded type parameters
change getter & setter methods well.
class trainingdata<t extends intent> extends info { private t intent; public t getintent() { homecoming intent; } public void setintent(t intent) { this.intent = intent; } ... }
java generics
No comments:
Post a Comment