以下代码在 Dart 中编译时没有错误或警告,但在运行时会失败。有什么方法可以选择接受 Dart 中泛型隐式向上转换的警告吗?
List<Object> objects = <int>[]; // implicit generic upcast
objects.add('hello'); // runtime error: type 'String' is not a subtype of type 'int' of 'value'
我的analysis_options.yaml中已经有implicit-casts: false
。
最佳答案
今天没有可用的静态分析。讨论此问题的跟踪问题以及链接的一些建议解决方案是 https://github.com/dart-lang/language/issues/213
关于Dart 隐式向上转型泛型警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56189511/