为什么不能在Dart中分配泛型变量?
void test<T1 extends num, T2 extends String>(T2 arg) {
// ↓ A value of type 'int' can't be assigned to a variable of type 'T1'. Try changing the type of the variable, or casting the right-hand type to 'T1'.
T1 t = 0;
// ↓↓↓↓ A value of type 'String' can't be assigned to a variable of type 'T2'. Try changing the type of the variable, or casting the right-hand type to 'T2'.
arg = 'Test';
}
1条答案
按热度按时间oyxsuwqo1#
下面的示例可能有助于理解泛型