Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limit T in a generic class to types that implement some interface

Tags:

dart

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?

like image 399
user1590636 Avatar asked Jun 08 '14 11:06

user1590636


1 Answers

class Question<T extends IAnswer>{
  String body;
  T answer;
}
like image 78
Günter Zöchbauer Avatar answered Sep 27 '22 18:09

Günter Zöchbauer