[groovy-user] Precedence implicit call() over real methods

5 views
Skip to first unread message

Alberto Vilches

unread,
Dec 4, 2011, 6:54:00 AM12/4/11
to us...@groovy.codehaus.org
Hi everybody. I have this snippet:

class Test {
    def foo() {
        def download = true
        if (download) download()
    }

    private download()
    }
}

In runtime, Groovy complains with: "No signature of method: java.lang.Boolean.call()"
That's because Groovy try to find first the implicit .call() method in the download variable, instead to invoke the real method in the same class.

It's a bug or it's a feature? Thank you! :)

--
Un saludo.
Alberto Vilches
Twitter: @albertovilches

Jochen Theodorou

unread,
Dec 4, 2011, 7:15:24 AM12/4/11
to us...@groovy.codehaus.org
Am 04.12.2011 12:54, schrieb Alberto Vilches:
> Hi everybody. I have this snippet:
>
> class Test {
> def foo() {
> def download = true
> if (download) download()
> }
>
> private download()
> }
> }
>
> In runtime, Groovy complains with: "No signature of method:
> java.lang.Boolean.call()"
> That's because Groovy try to find first the implicit .call() method in
> the download variable, instead to invoke the real method in the same class.
>
> It's a bug or it's a feature? Thank you! :)

feature, please use this.download() then instead, or rename your local
variable.

bye blackdrag

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Alberto Vilches

unread,
Dec 4, 2011, 11:25:19 AM12/4/11
to us...@groovy.codehaus.org
Pretty easy! thank you! And, what about this?

def chat = ""
render contentType:"text/xml", enconding:"UTF8" {
   chat {
       hello("guys")
   }
}

The builder fails because the chat variable takes precedence over the invokeMethod inside the builder...

Jochen Theodorou

unread,
Dec 4, 2011, 5:13:13 PM12/4/11
to us...@groovy.codehaus.org
Am 04.12.2011 17:25, schrieb Alberto Vilches:
> Pretty easy! thank you! And, what about this?
>
> def chat = ""
> render contentType:"text/xml", enconding:"UTF8" {
> chat {
> hello("guys")
> }
> }
>
> The builder fails because the chat variable takes precedence over the
> invokeMethod inside the builder...

foo {} is a shortcut for foo({}), thus same story. In that case you will
really have to change the name of your local variable.

Alberto Vilches

unread,
Dec 4, 2011, 7:02:47 PM12/4/11
to us...@groovy.codehaus.org
Thanks bdrag 

Alberto Vilches

unread,
Jan 24, 2012, 7:39:30 PM1/24/12
to us...@groovy.codehaus.org
Hey Bdrag, MrHaki writes a nice way to avoid my problem, just puttin "delegate." before the method call
:)
Reply all
Reply to author
Forward
0 new messages