But in what scenario does the dynamic behavior make sense ? You tell the 
compiler that a method does not have a return value - then you call that method 
using its return value, knowing it will always be null... ?-)
So the following:

final result = voidMethod() // looks like result might contain something 
interesting after the call... ?-)
is 100% equivalent to:
voidMethod()final result = null // ...oooor - not :-/

I feel at least in the @CompileStatic case using a void return value should 
fail at compile time - what do you think ?


-------- Ursprüngliche Nachricht --------Von: Paul King <pa...@asert.com.au> 
Datum: 29.08.18  10:35  (GMT+01:00) An: users@groovy.apache.org Betreff: Re: 
@CompileStatic void method returns null ? 
See also: https://issues.apache.org/jira/browse/GROOVY-8770
Which I presume was also to mimick dynamic behavior.
Cheers, Paul.

On Wed, Aug 29, 2018 at 4:42 AM Jochen Theodorou <blackd...@gmx.org> wrote:
On 28.08.2018 19:45, mg wrote:

> Since I just stumbled across this behavior while helping a junior 

> developer debug his code: Why does statically compiled Groovy (2.5.2) 

> return null from void methods, instead of raising a compile error ?



i was actually not aware we kept this logic for static compilation, but 

essentially it is like that because of dynamic Groovy, which derives 

this from the reflective and methodhandles based method invocation



bye Jochen


Reply via email to