在这个脚本中:
role Capturer {
method capturing(::CLASS:D: $ ) {
say "Working with ", $?CLASS, " that holds ", $.gist;
}
}
( <1 2 3 4> but Capturer ).capturing();
Run Code Online (Sandbox Code Playgroud)
定义了一个无参数的方法capturing,但是如果我这样调用它,我会得到:
Too few positionals passed; expected 2 arguments but got 1
in method capturing at captured-class.p6 line 4
in block <unit> at captured-class.p6 line 10
Run Code Online (Sandbox Code Playgroud)
我可以解决这个问题,给它一个虚拟的论点
Too few positionals passed; expected 2 arguments but got 1
in method capturing at captured-class.p6 line 4
in block <unit> at captured-class.p6 line 10
Run Code Online (Sandbox Code Playgroud)
然后返回:
Working with (List+{Capturer}) that holds (1 2 3 4)
Run Code Online (Sandbox Code Playgroud)
知道在那里等待什么样的论点吗?
任何参数真的,因为你定义的方法不是无参数的:
method capturing(::CLASS:D: $ )
^^^
Run Code Online (Sandbox Code Playgroud)
它定义了一个单一的、无名的位置参数。其中,没有任何类型规范,将接受Any. 所以你的问题的答案是:
知道在那里等待什么样的论点吗?
已经包含答案:Any值 :-)
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |