Jochen's example never required a cast in any Groovy version because his method 
took Object (a super type of Closure).

Had Jochen defined an interface, and defined the method to take the interface 
instead of Object or Closure, then before 2.2 an explicit cast from Closure to 
the interface type would have been required. After 2.2, Groovy implicitly 
converts the Closure to the interface type without the cast.

Jason

-----Original Message-----
From: alessio [mailto:aless...@gmail.com] 
Sent: Tuesday, December 01, 2015 4:05 PM
To: users@groovy.apache.org
Subject: Re: "External" closures, why?

On Tue, Dec 1, 2015 at 9:48 PM, Winnebeck, Jason 
<jason.winneb...@windstream.com> wrote:
> The explicit cast was needed before 2.2 only when you were trying to cast a 
> Closure to an instance of an interface (or other SAM type). In my example, 
> the closure implicitly can be casted to type X after 2.2. Before 2.2, you had 
> to explicitly cast the closure to X.
>
> Jochen's example worked because he didn't declare the type of his parameter. 
> When no type is declared, "Object" is used, which will take the Closure 
> directly.

So before 2.2 the cast was necessary in order to satisfy the method signature 
argument-wise, with a single Object argument being the default (and hence not 
requiring a cast)? Did I get that right?

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to