[英]Why is the type checking in Dart such strange?
给定代码
List<int> rawList = [0, 1, 2];
BuiltList<int> list = rawList.map((n) => n * 2);
编译成功但在运行时失败并出现错误
类型“MappedListIterable<int, int>”不是“BuiltList”类型的子类型
那么为什么它不会在编译阶段崩溃呢? 请解释一下,在 C# 和 Kotlin 之后我无法理解。
.map
返回一个Iterable<int>
,它不适合您的List<int>
。 您需要使用.toList()
将Iterable
转换为List
。
给定代码
List<int> rawList = [0, 1, 2];
BuiltList<int> list = rawList.map((n) => n * 2);
编译成功但在运行时失败并出现错误
类型“MappedListIterable<int, int>”不是“BuiltList”类型的子类型
那么为什么它不会在编译阶段崩溃呢? 请解释一下,在 C# 和 Kotlin 之后我无法理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.