Is it possible to replace groovy method for existing object?
- by Jean Barmash
The following code tried to replace an existing method in a Groovy class:
class A {
void abc() {
println "original"
}
}
x= new A()
x.abc()
A.metaClass.abc={-> println "new" }
x.abc()
A.metaClass.methods.findAll{it.name=="abc"}.each { println "Method $it"}
new A().abc()
And it results in the following output:
original
original…