AJOM | 19 Jul 2012 23:00
Picon

[groovy-user] modifying java class

Hi,
I have a groovy class as follows:
class GroovyInterceptor  {
	def run_it() {
		def b = [ doCallService: { "no service!!!" } ] as PlainOldJavaObject
		println b.myMethod("arg")
	}		
}

where PlainOldJavaObject is a java class:
public class PlainOldJavaObject  {
    public String myMethod(String x) {
        System.out.println("myMethod: args: " + x);
    	return doCallService(x);
    }

    public/protected/private String doCallService(String x) {
    	System.out.println("doCallService: args: " + x);
    	return "Hello from doCallService";
    }
}

The object in "b" is of class PlainOldJavaObject1_groovyProxy (result of
b.getClass.getName()) and b.myMethod("arg") calls the overridden
doCallService - but only when it is public or protected, not when defined as
private.
So how is this class PlainOldJavaObject1_groovyProxy generated? And what
happens when doCallService is private?

Thanks a lot for help
(Continue reading)

Jochen Theodorou | 20 Jul 2012 08:06
Picon
Gravatar

Re: [groovy-user] modifying java class

Am 19.07.2012 23:00, schrieb AJOM:
> Hi,
> I have a groovy class as follows:
> class GroovyInterceptor  {
> 	def run_it() {
> 		def b = [ doCallService: { "no service!!!" } ] as PlainOldJavaObject
> 		println b.myMethod("arg")
> 	}		
> }

the as PlainOldJavaObject will create a subclass with a doCallService 
method overridden, but of course only if that method is available for 
that. If it is private, this is not the case.

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


Gmane