如何创建类型别名

时间:2013-11-03 16:47:48

标签: types dart

如何为现有类型指定新名称?

假设我想给List<String>名称Directives,然后能够说directives = new Directives()

2 个答案:

答案 0 :(得分:7)

您无法定义别名。对于您的情况,您可以使用DelegatingList from quiver来定义Directives

import 'package:quiver/collection.dart';

class Directives extends DelegatingList<String> {
  final List<String> delegate = [];
}

答案 1 :(得分:4)

现在可以通过一个空的mixin

mixin ToAlias{}

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

class StuffInt = Stuff<int> with ToAlias;

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