【flutter】泛型类型判断

void main() {
	test<int>();
}

static testT<T>() {
	//判断T是否为某一类型或其子类
	print(List<T>() is List<num>);
	//得到T的类型
	print(_typeOf<T>());
}

static Type _typeOf<T>() => T;

注意这个在dartpad中是无法运行的

猜你喜欢

转载自blog.csdn.net/allanGold/article/details/108341275