The fact that you can call private methods is a bug in the Groovy language, not a feature. However, I believe this bug was introduced deliberately as a form of compromise when making some changes to the way closures behave.
Even though you can call private methods, you should not, because hopefully one day this bug will be fixed, and if your program relies on calling private methods it will be broken.
If you really insist on (ab)using this undocumented behaviour, you could try using something like ReflectionUtils to call private methods in parent classes.
Another workaround is to provide a method in the concrete class that calls the private method in the parent class. For example, the following code "works", but it still relies on accessing private members, which is bad
class Parent {
private foo() {println "foo"}
}
class Child extends Parent {
public bar() {super.foo()}
}
new Child().bar()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…