728x90
void main() {
Operation operation = add;
int result = operation(1, 2, 3);
print(result);
int result2 = cal(1, 2, 3, add);
print(result2);
}
// signature
typedef Operation = int Function(int a, int b, int c);
int add(int a, int b, int c) => a + b + c;
int sub(int a, int b, int c) => a - b - c;
int cal(int a, int b, int c, Operation operation) => operation(a, b, c);
typedef라고 하는데 잘 안 쓰이긴 하더라도 알고 있으면 좋을 것 같습니다.
반응형
'Programming > Dart, Flutter' 카테고리의 다른 글
[Android Studio]Flutter AVD 저장 폴더 위치 변경하기 (0) | 2022.01.14 |
---|---|
Flutter에서 hyperlink 구현하기 (0) | 2022.01.13 |
캐스케이드(Cascade Notation) (0) | 2022.01.11 |
얕은 복사(shallow copy), 깊은 복사(deep copy) (0) | 2022.01.11 |
ListView (0) | 2021.12.30 |
Comments