What is the difference between compile time constant and run time constant

余生长醉 提交于 2020-12-15 04:54:32

问题


I have Doubt when understand, Compile-time constant and runtime constant in Dart language, I am a beginner in dart language, I searched in google there is no article that covers this question, So thanks in advance


回答1:


There are no "run-time constants" in Dart, not the way the word "constant" is generally used. All constants are compile-time constants, meaning that their entire value can be determined at compile-time, they are deeply immutable, and the compiler can canonicalize the objects if two constant expressions end up with objects that have the exact same state.

The name "compile-time constants" wording comes from the specification which talks about "compile-time constant expressions". The results of those expressions are just called "constants".

You can say that final x = List<int>.unmodifiable([1]); defines a constant. It's certainly an object which cannot be modified, but it's not what would traditionally be called a constant in Dart terminology - it cannot be used in the places where the language requires a constant value.



来源:https://stackoverflow.com/questions/58859001/what-is-the-difference-between-compile-time-constant-and-run-time-constant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!