I’d like to re-implement a method of a Java class. For example, for "hi".length() to return 4. (How) Can I do that?
I know using SomeClass.metaClass I can get a reference to an existing method and define new (or overriding) method, but I can’t seem to be able to do that for existing Java methods.
Seems like it could be possible by abusing String metaClass. But the attempt I’ve done so far in groovy console didn’t led to the expected result :
outputs the sad
2I think you could take a look at Proxy MetaClass or Delegating metaClass.