Created
December 12, 2019 11:07
-
-
Save MariaMelnik/1cc6ffaf567f75b91f39053989eeb8ea to your computer and use it in GitHub Desktop.
dart: generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
void main() { | |
final listOfTasks = [Task<int, int>(1, calc), Task<int, int>(3, calc)]; | |
final task = listOfTasks.first; | |
method(task: task); | |
//тут я не могу узнать дженерик тип таски | |
} | |
typedef FutureOr<O> TaskFunction<I, O>(I arg); | |
class Task<I,O>{ | |
final O arg; | |
final TaskFunction<I,O> fun; | |
Task(this.arg, this.fun); | |
} | |
// void method({Task task}){ | |
void method<I,O>({Task<I,O> task}){ | |
print(task.runtimeType); | |
Bundle(task.fun); | |
} | |
int calc(int arg){ | |
return 1337; | |
} | |
class Bundle{ | |
final Function run; | |
Bundle(this.run); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment