我有一个泛型函数.我正在try 返回一个基于类型T
的值,
然而,我的函数似乎从未匹配过任何类型(请参见下面的代码):
int _getCollection<T>() {
print(T); // the actual type
print(T is ClockData); // ClockData is a class I created
// always returns false when passing _getCollection<ClockData>()
if (T is ClockData) {
return 1;
} else if (T is UserData) {
return 2;
} else {
throw Exception();
}
}