Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.5
-
None
Description
I was surprised by the following behavior:
class Person { Object invokeMethod(String name, Object args) { return false } } def person1 = new Person() Person.metaClass.newMethod = { -> return true } assert new Person().newMethod() assert person1.newMethod()
The last assert only works, if I set ExpandoMetaClass.enableGlobally() at the beginning of the script
The javadoc of enableGlobally says:
Call to enable global use of global use of ExpandoMetaClass within the registry. This has the advantage that inheritance will function correctly, but has a higher memory usage on the JVM than normal Groovy
The above use case should be added to the javadoc.
I guess with Groovy 2.0 things will become more intuitive anyway