您必须使用它noSuchMethod来执行此操作(请参阅在Dart中使用可变数量的参数或参数创建函数)
在班级:
class A {
noSuchMethod(Invocation i) {
if (i.isMethod && i.memberName == #myMethod){
print(i.positionalArguments);
}
}
}
main() {
var a = new A();
a.myMethod(1, 2, 3); // no completion and a warning
}
Run Code Online (Sandbox Code Playgroud)
或者在现场级别:
typedef dynamic OnCall(List l);
class VarargsFunction extends Function {
OnCall _onCall;
VarargsFunction(this._onCall);
call() => _onCall([]);
noSuchMethod(Invocation invocation) {
final arguments = invocation.positionalArguments;
return _onCall(arguments);
}
}
class A {
final myMethod = new VarargsFunction((arguments) => print(arguments));
}
main() {
var a = new A();
a.myMethod(1, 2, 3);
}
Run Code Online (Sandbox Code Playgroud)
第二个选项允许代码完成myMethod并避免警告.
| 归档时间: |
|
| 查看次数: |
597 次 |
| 最近记录: |