groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Theodorou" <blackd...@gmx.org>
Subject Aw: Do closures always return a value?
Date Fri, 04 Dec 2015 10:50:44 GMT


> Gesendet: Freitag, 04. Dezember 2015 um 11:36 Uhr
> Von: "Felix Dorner" <felix.dorner@gmail.com>
> An: "users@groovy.apache.org" <users@groovy.apache.org>
> 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

Mime
View raw message