[Dart] final vs const
vs const Final Dart
2023-09-14 08:59:14 时间
void main() { var a = 1; print(a); int b = 2; print(b); final c = 'Hello'; // c = 'Hello again'; // Uncomment to throw print(c); const d = 'World'; print(d); }
If we attempt to reset 'final' to a different value, we will get an error. The difference in practice between const
and final
is you use final
when certain instance variables belong into classes.
final can be set in runtime, but const can only be set during compile time:
const int time = Date.now() // ERROR final int time = Date.now() // GOOD
相关文章
- luajit vs php7,Luajit编译
- PyCharm vs Spyder:两个Python IDE的快速比较
- VS多行注释快捷键_vs2015注释快捷键
- Java vs Kotlin
- vs2008连接tfs2013_VS连接SQL网页登录
- 外行杂谈论—聊聊看板 vs 大屏的区别(有彩蛋)
- GreatSQL vs MySQL性能测试来了,速围观~
- VS Code的7个开源替代品
- 教你Visual Studio Code(VS Code)如何查询PostgreSQL拓展安装教程图解
- 数据库VS连接Oracle数据库:轻松实现连接(vs连接oracle)
- 性能比较比较分析:VS编译器与Oracle数据库的性能差异(vs与oracle数据库)
- VS如何连接MySQL数据库(vs连接mysql数据库)
- 如何编写 VS Code 扩展
- 15 个提高工作效率的 VS Code 键盘快捷键
- VS连接MSSQL:解决数据库连接问题(vs连接 mssql)
- VS连接SQL Server:让你从此走向数据库的新世界(vs连sqlserver)
- 提供安全服务【使用VS保障SQL Server安全性】(vs给sqlserver)
- vs安装redis让你享受更高性能(vs 安装redis)
- 比较视图VS与Redis(vs与redis)
- VS中如何优雅地操作Redis(vs操作redis)