飞镖,对泛型有限制吗? [英] Dart, constraints on Generics?

查看:82
本文介绍了飞镖,对泛型有限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有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.

这篇关于飞镖,对泛型有限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆