What is correct way to change method signature for single java object. Suppose I wanna change toString method.
myObject.metaClass.toString = { pritln "hello world" }
Looks like this code has problems. If I pass my object into other Java compiled object original toString will be called.
Other solution creates wrapper Object. It has different class from original one so it doesn’t satisfy me
Added:
1. I can’t control creation process
2. I don’t know how object was instantiated
So there is no groovy way to solve this problem?
The only solution is to create Java wrapper class, wrap all methods and change one? This is a …
any changes you make to the metaClass are only visible to groovy.
java has no idea the metaClass exists, so obviously cannot call any replacement methods defined by it