问题
This snippet used to work properly with Groovy 2.1.0:
class User {
private String sayHello() {
return "hello"
}
}
assert new User().sayHello() == "hello"
User.metaClass.sayHello = {
return "goodbye"
}
assert new User().sayHello() == "goodbye"
but it does not work anymore in Groovy 2.4.3. Does anybody know how to override the behaviour of a private method with Groovy (if possible)?
来源:https://stackoverflow.com/questions/31938551/overriding-private-method-with-metaclass-in-groovy