Dart Memo : final & const

Dr_Skele·2023년 1월 2일
0

Dart

목록 보기
2/5

Both final and const value cannot be modified. Then, what's so different?
Difference between final and const is the 'const' value needs to be a constant value that can be known at the compile-time. On the other hand, 'final' value can be provided at the run-time.

void main() {
  String getName() => 'my name';

  //const name1 = getName(); //Const variables must be initialized with a constant value.
  final name2 = getName();
}
profile
Tireless And Restless Debugging In Source : TARDIS

0개의 댓글