“Const vs Final Trup” Kod odpowiedzi

Final vs Const Dart

Const
Value must be known at compile-time, const int year  = 2022;
Can't be changed after initialized.

Final
Value must be known at run-time, final birthday = getBirthDateFromDB()
Can't be changed after initialized.
Hey Argon

Const vs Final Trup

final variable can only be set once and it is initialized when accessed.
(for example from code section below if you use the value of 
biggestNumberOndice only then the value will be initialized and 
memory will be assigned).

const is internally final in nature but the main difference is that 
its compile time constant which is initialized during compilation even
if you don't use its value it will get initialized and will take space
in memory.

Variable from classes can be final but not constant and if you want a
constant at class level make it static const.
Viper

Odpowiedzi podobne do “Const vs Final Trup”

Pytania podobne do “Const vs Final Trup”

Więcej pokrewnych odpowiedzi na “Const vs Final Trup” w Dart

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu