1

运行groovyshv2.3.6:

groovy:000> def f = {x -> x}
groovy:000> f(1)
ERROR groovy.lang.MissingMethodException:
No signature of method: groovysh_evaluate.f() is applicable for argument types: (java.lang.Integer) values: [1]
Possible solutions: is(java.lang.Object), run(), run(), find(), any(), any(groovy.lang.Closure)

这个错误是 on 的已知错误closuregroovysh

4

1 回答 1

1

是的,这是一个已知问题,在 groovysh 中使用 def 不会像您期望的那样工作。使用或使用数据类型声明的变量def不会存储在 GroovyShell 的绑定中,这是 shell 查找在 repl 中输入的名称的地方。

如果您像这样声明没有 def 的变量,它将起作用:

f = { x -> x }
于 2014-10-07T21:25:00.570 回答