一个通用方法getter或这是什么



我在moctail中遇到过这个,什么是"当";在函数签名-一个通用方法getter中,为什么可以在测试中使用它作为函数?

When<T> Function<T>(T Function() x) get when {
if (_whenCall != null) {
throw StateError('Cannot call `when` within a stub response');
}
_whenInProgress = true;
return <T>(T Function() _) {
try {
_();
} catch (_) {
if (_ is! TypeError) rethrow;
}
_whenInProgress = false;
return When<T>();
};
}

when是一个返回泛型函数的getter。该泛型函数将另一个函数作为参数,并返回一个When<T>

When<T> Function<T>(T Function() x) get when { ... }
_________________________________/  ^   ^
|                    |   |
|                    |   +-- Name of the member
|                    |
|                    +------ Member is a getter
|
+--------------------------- Return type of the getter

最新更新