Dart Typedefs示例

typedef int Check(Object a, Object b);

class Darttypedef {

	Check compare;

	Darttypedef(this.compare);
}

int sort(Object a, Object b) => 0;

main() {

	Darttypedef collection = new Darttypedef(sort);
	if(collection.compare is Function){
	  print(true);
	}

	if(collection.compare is Check){
	  print(true);
	}

}
  • 还可以使用泛型Typedefs:

通用typedefs示例

typedef int Check<T>(T a, T b);

class TypedefDart<T> {
Check<T> compare;
TypedefDart(this.compare);

}

main() {
TypedefDart<int> s = new TypedefDart<int>((a,b) => a - b);

if(s.compare is Check<int>){
  print(true);
}
}
在DART中 typedefs是什么

Dart中的Typedefs

DART typedefs或者函数类型别名提供了一个函数名,您可以在声明字段和返回类型时使用它。typedef包含函数类型为赋值变量时的信息。

日期:2020-04-11 23:04:02 来源:oir作者:oir