Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-2635

Can't replace a setProperty method declared in an object with metaclass directives.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.5.4
    • None
    • groovy-runtime
    • None

    Description

      The following script:

      class Test {
          void setProperty(String name, value) {
              println "instanceSetProperty"
          }
      
          void myMeth() {
              println 'instanceMyMeth'
          }
      }
      
      Test.metaClass.setProperty = { String name, value ->
         println 'metaSetProperty'
      }
      Test.metaClass.myMeth = { ->
         println 'metaMyMeth'
      }
      Test test = new Test()
      test.a = 'b'
      test.myMeth()
      

      yields:

      instanceSetProperty
      metaMyMeth

      The setProperty method added via the metaclass is ignored.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hans_d Hans Dockter
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: