Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2242

Missing information in Javadoc of ExpandoMetaClass.enableGlobally()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.5
    • 2.4.6
    • Documentation
    • 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

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            hans_d Hans Dockter
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: