Not a parser issue, as only closures can be used as the last argument outside 
of the parentheses of a method invoked with explicit parentheses.  (The closure 
is not recognized as the 2nd arg, but the last arg)
The Apache Groovy programming language - Style guide (groovy-lang.org)

You could also do this    test true, "oops"
-Spencer

    On Thursday, August 15, 2024 at 07:47:01 AM EDT, OCsite <o...@ocs.cz> 
wrote:  
 
 Hi there,
is this my fault, for I missed some documentation somewhere, or a parser fault, 
for it should have recognised the bool as the 1st and string as the 2nd 
argument and just call “test” with “true, 'oops'” in the last case (as I've, 
perhaps mistakenly, assumed)?
===
782 ocs /tmp> <q.groovy

def test={ boolean always=false, val ->

  println "$always: $val"

}

test "hi"

test(true, "ha")

test(true) { -> "ho" } // a closure is properly recognised as 2nd arg

test(true) "oops" // a string is not?!?

782 ocs /tmp> /usr/local/groovy-4.0.0-alpha-1/bin/groovy q

false: hi

true: ha

true: ho

false: true

Caught: java.lang.NullPointerException: Cannot get property 'oops' on null 
object

783 ocs /tmp> 
===
Thanks and all the best,OC  

Reply via email to