22 Feb 2005 18:04
Re: [groovy-dev] | ambiguity
On 22 Feb 2005, at 16:40, Russel Winder wrote:
> On Tue, 2005-02-22 at 10:46 -0500, Chris Poirier wrote:
>
> [ . . . ]
>
>> someObject.someFunc { x, y = 1 | 2, z = 0 |
>> println x
>> println y
>> println z
>> }
>
> Presumably this is solved by using parentheses:
>
> someObject.someFunc { x , y = ( 1 | 2 ) , z = 0 |
> println x
> println y
> println z
> }
Nearly. The final expression is ambiguous too (z = 0 |). In New Groovy
the following works...
def c = { (x, y = 1 | 2, z = 0)|
println x
println y
println z
}
(though the runtime doesn't yet handle closures with default arguments)
This extra level of verbosity is only an issue if you're supplying
default parameter values in the closure. For regular typed closures you
can do
def x = {|String x, int y| ... }
James
-------
http://radio.weblogs.com/0112098/
RSS Feed