## Dart Base Language Learning — Constants

Type declarations can be omitted

final String a = 'final-string-dart';
final a = 'final-a-dart'

const String a = 'const-string-a';
const a = 'const-a';
Copy the code

No more assignments can be made after initialization

final a = 'final-a';
a = 'abc';

const a = 'const-a';
a = 'abc';

Copy the code

Cannot be used together with var

final var a = 'final-var-a';
const var a = 'const-var-a';
Copy the code

Const assignment declarations can be omitted

const List ls = const [11.22.33];
const List ls = [11.22.33];
Copy the code

The difference between

The value to be determined

final dt = DateTime.now();

const dt = const DateTime.now();
Copy the code

Immutability is transferable

final List ls = [11.22.33];
ls[1] = 44;

const List ls = [11.22.33];
ls[1] = 44;
Copy the code

Duplicate creation in memory

final a1 = [11 , 22];
final a2 = [11 , 22];
print(identical(a1, a2));

const a1 = [11 , 22];
const a2 = [11 , 22];
print(identical(a1, a2));
Copy the code

PDF document sorting:

Dart Basic Language Learning – Part 1. PDF

Blog Source: Blog of rainy Night