如何创建类型别名 [英] How do I create a type alias

查看:64
本文介绍了如何创建类型别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为现有类型赋予新名称?

How do I give a new name to already existing type?

假设我要赋予 List< String> code>名称 Directives ,然后可以说出 directives = new Directives()

Let's say I want to give to a List<String> the name Directives and then be able to say directives = new Directives().

推荐答案

现在可以通过空的mixin

It is possible now via an empty mixin

mixin ToAlias{}

class Stuff<T> {
  T value;
  Stuff(this.value);
}

class StuffInt = Stuff<int> with ToAlias;

main() {
  var stuffInt = StuffInt(3);
}

这篇关于如何创建类型别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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