是否有cart功能的Dart等效语法来指定通用类型的类型约束,例如以类似C#的语法,其中TBase为SomeType :
Is there a Dart equivalent syntax to the c# ability to specify type constraints on a generic type, e.g. in C#-like syntax where TBase is SomeType:
class StackPanel<TBase> extends Panel<TBase> where TBase : SomeType{ }推荐答案
您可以这样指定类型约束:
You can specify type constraints like this :
class StackPanel<TBase extends SomeType> extends Panel<TBase> { }语言规范说:
类型参数 T 可以带有 extends 子句后缀,该子句指定上限表示 T 。如果没有extends子句,则上限为对象。如果类型参数是其上限的超类型,则这是静态类型警告。类型变量的边界是类型注释的一种形式,对生产模式下的执行没有影响。
A type parameter T may be suffixed with an extends clause that specifies the upper bound for T. If no extends clause is present, the upper bound is Object. It is a static type warning if a type parameter is a supertype of its upper bound. The bounds of type variables are a form of type annotation and have no effect on execution in production mode.
更多推荐
飞镖,对泛型有限制吗?
发布评论