Groovy does not support checking empty closure at runtime AFAIK, but we could 
check and set some property to closure while compiling, then get the property 
at runtime. It will be an new improvement, not sure if others like it or not.

Cheers,
Daniel Sun

On 2021/02/17 15:06:47, OCsite <o...@ocs.cz> wrote: 
> Hi there,
> 
> is it possible to reliably recognise an empty closure, i.e., „{}“, 
> programmatically? 
> 
> def foo(Closure bar) {
>   if (?bar-is-empty?) throw new Exception('The closure cannot be empty!')
>   else bar()
> }
> foo { println "ok" } // OK
> foo { 1 } // OK
> foo { } // throws
> 
> Thanks!
> OC

Reply via email to