We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 230bc07 commit c1e8b56Copy full SHA for c1e8b56
constants_and_finals.dart
@@ -0,0 +1,23 @@
1
+void main() {
2
+/*final: can only be set once and is initialized when accessed
3
+ - only consume memory if used
4
+ constant: implicitly final but it is compile-time constant
5
+ i.e. it is initialized during compilation - it will consume memory no matter
6
+ if you're using it or not
7
+ NOTE: Instance var can be final but cannot be const.
8
+ - If you want a const at class level then make it static const
9
+ */
10
+
11
+ final cityName = "Delhi";
12
+ //String is optional
13
14
+ const double PI = 3.14;
15
16
+ Circle circle = new Circle();
17
+ print(circle.color);
18
+}
19
20
+class Circle {
21
+ final color = "Red";
22
+ static const PI = 3.14;
23
0 commit comments