What is the dart function type syntax for declaring a variable?

I know that you can specify function types in the formal arg list, but how would this be done for variable variables? I would like to do this:

class A<T> { int compare(T a, T b); } 

where compare is a function variable with the corresponding type. I would like to be able to write:

 A a = new A(); a.compare = ... 
+4
source share
1 answer

You can use typedef :

 typedef int Comparison<T>(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)); } 
+7
source

Source: https://habr.com/ru/post/1491133/


All Articles