1

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

subhashchandru
  • 97
  • 1
  • 10
  • Possible duplicate of [What is the difference between the "const" and "final" keywords in Dart?](https://stackoverflow.com/questions/50431055/what-is-the-difference-between-the-const-and-final-keywords-in-dart) – julemand101 Nov 14 '19 at 16:01
  • not exactly expected answers given, will be helpful if it has been more explict@julemand101 – subhashchandru Nov 14 '19 at 16:06
  • Well, I don't really know how it can be more detailed explained then... – julemand101 Nov 14 '19 at 16:53

2 Answers2

4

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.

lrn
  • 64,680
  • 7
  • 105
  • 121
0

compile-time and run time

Compile-time and Runtime are the two programming terms used in software development. Compile time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running.

What is the const keyword and why should we care?

The const keyword is used when the variable's value is known at compile-time and never changes. In other words, the compiler knows in advance what value is to be stored in that variable.

you can refer to this link [https://medium.com/flutter-community/the-flutter-const-keyword-demystified-c8d2a2609a80#:~:text=The%20const%20keyword%20is%20used,1%20and%20will%20not%20change]

Rishal
  • 194
  • 5