반응형
void main() {
int age; // mutable한 속성을 가지고 있음
age = 20;
age = 50;
}
Final variable can be set only once.
Final 변수는 값을 한번 설정할 수 있다. 런타임 시에 상수화 된다.
final 변수는 rebuild 될 수 있음
a const variable is complie-time constant.
const 변수는 컴파일 시에 상수가 된다. 선언과 동시에 초기화를 해야한다
Compile-time constant = Run-time constant
void main() {
final int myFinal = 30;
const int myConst = 70;
}
// final, const는 제어자. 변수에 제한을 검
// 둘다 새로운 값을 할당할 수 없다.
- The final variable 'myFinal' can only be set once[Immutable 속성]
- Constant variables can't be assigned a value
class Person {
final int age;
String name;
Person(this.age, this.name);
}
void main() {
Person p1 = new Person(21, 'Tom');
print(p1.age);
}
반응형
': IT > Flutter' 카테고리의 다른 글
[Flutter/Dart] Stateless Widget (0) | 2023.01.29 |
---|---|
Visual Studio - develop for Windows (the doctor check crashed) (0) | 2022.06.08 |
Focus (0) | 2022.05.21 |
플러터 2.0 버튼 (0) | 2022.03.03 |
Collection and Generic (0) | 2022.03.03 |