[英]Dart - Class with Generic that extends a Second Class with a Second Generic - Is this possible?
Here is the code I would like to do:这是我想做的代码:
abstract class StateBase<E> {
void restoreState( E target );
void saveState( E source );
}
class StateController<T extends StateBase<E>> {
final List<T> _states = [];
void takeSnapshot( E target ) { ... }
void addState( T state ) { ... }
But in the line:但在这一行:
class StateController<T extends StateBase<E>> {
When I add the <E> bit it gives me the error:当我添加 <E> 位时,它给了我错误:
The name 'E' isn't a type so it can't be used as a type argument.
Dynamic typing means I can get by with out the 'E' bit, and just use 'StateBase', but I'd prefer the type checking that I can get using the second generic E.动态类型意味着我可以不用 'E' 位,只使用 'StateBase',但我更喜欢使用第二个通用 E 可以获得的类型检查。
Is this possible to do in Dart?这可以在 Dart 中做到吗?
Thanks for your time!谢谢你的时间!
只需添加E
作为另一个类型参数:
class StateController<E, T extends StateBase<E>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.