【发布时间】:2020-12-20 21:06:33
【问题描述】:
给定代码
List<int> rawList = [0, 1, 2];
BuiltList<int> list = rawList.map((n) => n * 2);
编译成功,但在运行时失败并出现错误
type 'MappedListIterable
' 不是 type 的子类型 '内置列表'
那么为什么它不会在编译阶段崩溃呢?请解释一下,在 C# 和 Kotlin 之后我无法理解。
【问题讨论】:
-
该代码实际上给了我编译时错误(至少 IDE 显示它是错误的)
-
BuildList的声明是什么? -
@BambinoUA 它来自built_collection pub.dev/packages/built_collection
标签: flutter generics dart typechecking compile-time-type-checking