> Gesendet: Freitag, 04. Dezember 2015 um 11:36 Uhr
> Von: "Felix Dorner" <[email protected]>
> An: "[email protected]" <[email protected]>
> Betreff: Do closures always return a value?
>
> Hi,
> 
> given that I don't need a return statement in groovy, do closures always 
> return a value? 

yes

> Is it possible to declare a closure to have type 'void' somehow?

currently not

> I would like to exploit this somehow like this:
> 
> def someMethod(Closure closure){
> 
>      if (closure has no return value, or is somehow defined to be 'void'){
>        closure()
>      } else {
>              if (closure()){
>                    doSomething()
>              } else {
>                    doSomethingElse()
>              }
>      }
> }

normally it makes no sense to have a logic like this. If you have something 
specific we can discuss the case, maybe it is an exception (or strange 
requirement ;)). But if it does in your case I suggest using either additional 
parameters or different method names and split the cases

bye Jochen

Reply via email to