19 Jul 2012 23:00
[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)
RSS Feed