What is the dart function type syntax for variable declaration?

dart

Solution

You can use `typedef` :

typedef Comparison<T> = int Function(T a, T b);

class A<T> {
  Comparison<T> compare;
}

main() {
  A a = new A<int>();
  a.compare = (int a, int b) => a.compareTo(b);
  print(a.compare(1, 2));
}

Problem

I know you can specify function types in formal arg list, but how would I do this for instance variables? I would like to do this: ``` class A<T> { int compare(T a, T b); } ``` where compare is a function variable with the appropriate type. I would like to be able to write: ``` A a = new A(); a.compare = ... ```

Original source