[Dart] final vs const
2024-10-06 05:32:28
void main() {
var a = ;
print(a); int b = ;
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
最新文章
- 【QT】C++ GUI Qt4 学习笔记5
- (博弈论)hdoj 1079 Calendar Game
- transport
- max_size, capacity and size 的区别
- Cakephp 创建无模型的Controller
- linux初识-02常用命令
- hdu 1234
- 数据库 版本号是 661,打不开。此server支持 655 和更早的版本号。不支持降级路径
- postgresql 抽样查询
- MySQL操作符
- python开源项目及示例代码(转)
- Java面向对象的特征
- 渐变UI
- oracle如何创建存储过程和调用
- Shell脚本 | 性能测试之CPU占有率
- TOMCAT服务器配置域名
- Undo日志文件的产生和使用
- MySql 简单统计查询消耗时间脚本
- pytorch梯度裁剪(Clipping Gradient):torch.nn.utils.clip_grad_norm
- (五)HttpClient 连接超时及读取超时