dart - Variable declaration in Dart
问题描述
I'm just beginning to learn Dart and Flutter and I was wondering if there is any difference in the following declarations?
final List<WordPair> _suggestions = <WordPair>[];
and
final _suggestions = <WordPair>[];
They both seem to exhibit the same behaviour but I'm wondering if there is some underlying difference?
I prefer the first declaration as I'm coming from a C/C++ back ground
解决方案
他们之间根本没有区别。第二种语法在这里只是为了避免无意义的重复。
通常你应该更喜欢 Dart 中的简写。 根据 dart 的 DO/DON'T,在某些情况下您可能希望使用完整的语法。
final List<Foo> globalVariable = <Foo>[];
void func() {
final localVariable = <Foo>[]
}
推荐阅读
- c++ - 使用可用的编译指示优化 Vivado HLS 中的降噪算法
- mysql - Omitempty 字段不起作用,如何从响应正文中删除空结构?
- css - 制作自定义单选按钮css
- python - django 的 Azure SQL 数据库连接错误
- sql - db2 表中的 join 语句
- python - Python 多维列表初始化 ...或纯 Python 等价于 numpy.zero
- snowflake-cloud-data-platform - 从 AWS S3 加载到 Snowflake 时从 ETC 转换为 UTC 时区
- javascript - Electron JS 高效地监视大量文件
- python - Glue ETL:如何使用 AWS 管理控制台将配置文件引用为额外文件?
- spring-boot - 使用 Spring Data 需要基于外键和 Order BY 值的不同记录