【发布时间】:2019-10-15 11:21:52
【问题描述】:
我正在尝试调用一个接受另一个函数作为参数的函数。
当我尝试使用泛型进行概括时,我收到以下错误
错误:不能将参数类型“..”分配给参数类型“..”。
class MyType {}
typedef MyFunctionType = void Function(Function <MyValue extends MyType> (MyValue?, MyValue));
class MyClass <MyValue extends MyType> {
late MyFunctionType myFunc;
MyClass(this.myFunc) {
(observer) => this.newValues(observer.oldValue,observer.oldValue);
}
MyClass <MyValue> _select(MyValue Function(MyValue) selector) {
var observerFunc = (oldValue,newValue) {
};
return MyClass((observer) => this.observe(observerFunc));
}
void observe(MyFunctionType func){
this.myFunc = func;
}
void newValues(MyValue oldValue, MyValue newValue) {
// TODO Add functionality
}
}
以下是错误
error: The argument type 'void Function(dynamic Function<MyValue₀ extends MyType>(MyValue, MyValue))' can't be assigned to the parameter type 'void Function(dynamic Function<MyValue extends MyType>(MyValue, MyValue))'. (argument_type_not_assignable at [dartTry] test/Params2Arguments.dart:16)
【问题讨论】:
标签: dart