飞镖,对泛型有限制吗?

编程入门 行业动态 更新时间:2024-10-26 17:28:15
本文介绍了飞镖,对泛型有限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

飞镖,对泛型有限制吗?

本文发布于:2023-10-17 11:06:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500709.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:飞镖   泛型有

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!