[Dart] final vs const
Posted answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Dart] final vs const相关的知识,希望对你有一定的参考价值。
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.
以上是关于[Dart] final vs const的主要内容,如果未能解决你的问题,请参考以下文章