if I have two methods in a java class like below, the public method can be overridden but not the private one.
public class JavaClass {
public void echo() {
System.out.println("Echo'd from Java Class");
}
private void doSomethingElse() {
System.out.println("Something else happening from Java Class");
}
}
If I try to override it like so:
JavaClass pojo = new JavaClass()
pojo.metaClass.echo = {
println "Echo overridden!"
}
pojo.metaClass.doSomethingElse = {
println "This won't be overridden"
}
println pojo.echo
println pojo.doSomethingElse
The private method is not overridden.
POJO's use the expandoMetaClass which is, from my understanding, associated to the Java class through the MetaClass Registry. The ExpandoMetaClass should have all method calls delegated to it. I can see in debugger that the ExpandoMetaClass is there and the new method is defined within the metaClass, but it's not being used! What is happening here?
Edit: Note I am not asking IF i can, I know I can't. I'm asking why it doesn't work. It works for public methods as you can see from the example above if you run it.