Reputation: 1194
In dart consider the following
class Question<T>{
String body;
T answer;
}
//an interface
class IAnswer{
String Value()=>this.toString();
}
I need T to be limited to types the for example implement the interface IAnswer, is that possible without having to check if T is IAnswer and throw and exception in the Question constructor?
Upvotes: 10
Views: 1198
Reputation: 657198
class Question<T extends IAnswer>{
String body;
T answer;
}
Upvotes: 7