groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Static imports seem to win over a method in closure's delegate
Date Fri, 12 Apr 2019 21:14:57 GMT
Using import aliases can be a good workaround for such a case.

On Sat, Apr 13, 2019 at 4:58 AM Jochen Theodorou <blackdrag@gmx.org> wrote:

> On 10.04.19 16:05, Herrendorf Johannes wrote:
> > Hi Groovy users,
> >
> > I’m currently building a DSL in groovy and found some strange behaviour
> > I have no explanation for: If a method pointer with name "myMethod" is
> > imported as static import and a closure has a delegate with a method
> > "myMethod" and it's delegation strategy is set to "DELEGATION_ONLY", the
> > imported method is always called inside the closure - the delegate
> > property seems to be ignored.
>
> two things to always remember:
> * closure delegation is a runtime mechanism, it has no influence on
> static compiled features
> * static imports are compiled statically
>
> The later is not because we want this, but because we have to more or
> less. And it is painful. I can imagine a system where this is not
> required, but that is far from easy or efficient.
>
> [...]
> > import static mailinglist.SomeOtherClass.myMethod
> [...]
> >           // dispatched to SomeOtherClass.myMethod; correct
> >          myMethod "Hello"
> >          closureStuff {
> >              // dispatched to SomeOtherClass.myMethod, but I expected
> that
> >                       // it's dispatched to ClosureDelegate.myMethod
> instead
> >              myMethod "Good Morning"
> >          }
> [...]
> > Am I missing something or is this a bug? Thanks for your help in advance!
>
> In short it is a limitation. I am not sure we can really do something
> against that.
>
> bye Jochen
>
>

Mime
View raw message