Dart, Flutter

typedef

옥수수빵 2022. 1. 17. 15:10
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라고 하는데 잘 안 쓰이긴 하더라도 알고 있으면 좋을 것 같습니다.

반응형