16 May 12:25
Re: [groovy-user] Problem using GroovyInterceptable implementation from Java
From: tugwilson <tug@...>
Subject: Re: [groovy-user] Problem using GroovyInterceptable implementation from Java
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-05-16 10:25:33 GMT
Subject: Re: [groovy-user] Problem using GroovyInterceptable implementation from Java
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-05-16 10:25:33 GMT
Jochen Theodorou wrote:
>
> [snip]
>> This feature would help the Java developers to adopt Groovy code into
>> their
>> existing Java project.
>> The lack of ability to use Groovy interceptors from Java code is kind of
>> disappointing for me...
>> Every Groovy book declares that it is so easy to integrate Groovy to
>> Java,
>> but noone mentions the "small things" about the integration, like that
>> the
>> Groovy can loose its dynamic behavior in Java.
>
> that's because (a) it is no secret and (b) we had the guideline to let
> Groovy behave like Java when looking at Groovy from Java in the past.
> For example you don't expect 1.plus(1) in Java, when you do 1+1.
>
If you do consider this for Groovy 2.0 there's an odd corner case you have
to look out for. If you subclass the Groovy class in Java and override the
method then call the overridden method via super you need to avoid a stack
overflow because of recursion.
class Foo { // Groovy
def bar() {
}
}
class Bar extends Foo { // Java
public Object bar() {
return super.bar();
}
}
The stub generated for foo in Foo has to check that it has not been
overridden with a Monkey Patch or Category and then, if not, execute the
method which was declared on Foo (which is one of the reasons why I make
these methods static). If you do a straightforward dynamic dispatch via the
normal MetaClass mechanism you get infinite recursion.
John Wilson
--
--
View this message in context: http://www.nabble.com/Problem-using-GroovyInterceptable-implementation-from-Java-tp17229195p17271651.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
RSS Feed