1

Run groovysh v2.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)

Is this error a known bug for closure on groovysh?

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
sof
  • 9,113
  • 16
  • 57
  • 83

1 Answers1

1

Yes, this is a known issue, using def in groovysh doesn't work like you'd expect. Variables declared with def or with a datatype don't get stored in the GroovyShell's binding, which is where the shell is looking for the names entered in the repl.

It will work if you declare the variable without def like this:

f = { x -> x }
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • Eliminating `def` keyword from named `closure` is actually more appreciated when `closure` is thought of an `expression`. – sof Oct 07 '14 at 21:39