【发布时间】:2020-03-14 19:42:59
【问题描述】:
考虑这个示例代码:
void main() {
List<int> array = <int>[];
for (int i = 0; i < 5; i++) {
array.add(i);
}
Iterable<int> newList = array.where( (value) => value % 2 == 0 );
printFunction(array);
printFunction(newList);
}
void printFunction(List<int> list) {
print(list);
}
这段代码编译成功,但在运行时当然会抛出异常,因为它无法运行printFunction(newList)的代码,除非在传递newList之前调用toList()
为什么编译器在这种情况下没有抛出异常???
【问题讨论】:
标签: flutter exception dart compile-time-type-checking