Given this Groovy program:
def f(x) { return x }
g = f
println g(42)
When feeding the program to the Groovy (version 2.4.12) interpreter, an error message is printed:
groovy.lang.MissingPropertyException: No such property: f for class: x at x.run(x.groovy:3)
However, changing the program to
def f = { x -> x }
g = f
println g(42)
Makes the interpreter print '42', as expected.
Why are these two definitions of f
treated differently? Is there a way to adjust the definition of g
such that the former version runs (maybe using the &.
operator)?