I've just started learning Groovy. And I got into this: https://groovy-lang.org/style-guide.html#_return_keyword_optional So, 'return' can be omitted at the end in a method definition. Alright. Even though I would prefer using it personally, I wanted to take a look. I tested some simple cases to figure out how it works:
e.g. demo.groovy:
def a1 = { return { return 'hi'} }()
println a1
def a2 = { return {'hi'} }()
println a2
def a3 = { {'hi'} }()
println a3
def a4 = { {-> 'hi'} }()
println a4
I ran the script, and the result was:
demo$_run_closure1$_closure5@21c64522
demo$_run_closure2$_closure6@460f76a6
hi
demo$_run_closure4$_closure7@1922e6d
Starting from the case a1, I omitted keywords 'return' one at a time. They are the cases a2, and a3. What made me scratch my head is the case a3. I expected the closure to be returned like the cases a1 and a2. But it returned 'hi', not the closure itself. So I added another test case a4 and then it worked as expected.
I tried to search some documentation about it, but couldn't find a proper one. Why does it return 'hi' not a closure object?
Thanks in advance.
FYI, my groovy version is:
Groovy Version: 3.0.7 JVM: 15.0.1 Vendor: Oracle Corporation OS: Mac OS X
