Dart-静态类型化列表中的值
为什么这不是Dart中的错误Dart-静态类型化列表中的值,dart,dart-editor,dartium,Dart,Dart Editor,Dartium,为什么这不是Dart中的错误 List<String> listA = ['aa', 1, 'cc']; //not compile time error, not run time error?? listA=['aa',1',cc']//非编译时错误,非运行时错误?? 我正在使用Dart编辑器。编写列表a=['aa',1',cc']就像写列表a=['aa',1',cc']。['aa',1,'cc']的运行时类型是List,它与您使用的类型注释List兼容 如果您想定义字符串列
List<String> listA = ['aa', 1, 'cc']; //not compile time error, not run time error??
listA=['aa',1',cc']//非编译时错误,非运行时错误??
我正在使用Dart编辑器。编写列表a=['aa',1',cc']代码>就像写列表a=['aa',1',cc']代码>。['aa',1,'cc']
的运行时类型是List
,它与您使用的类型注释List
兼容
如果您想定义字符串列表
以在编辑器中显示警告并在运行时显示错误,您应该选择:
listA=['aa','cc'];
//或
最终列表a=['aa','cc'];
为了更好地理解,以下是一些示例:
print((['aa',1,'cc']).runtimeType);//列表
打印((['aa','cc'])。运行时类型);//列表
打印((['aa','cc'])。运行时类型);//列表
打印((['aa','cc'])。运行时类型);//列表
列表l1=['aa',1',cc'];//好啊
列表l2=['aa','cc'];//好啊
列表l3=['aa','cc'];//好啊
列表l4=['aa','cc'];//编辑器中的警告+运行时错误
Thx<代码>列表A=['aa',1',cc']代码>确实在编辑器和运行时错误中给了我警告。dart2js
不会因为这样的错误而停止编译,这是真的吗?为什么这不是编译时错误?