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.

    Details

    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5.4
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      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.

        Issue Links

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Hans Dockter
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development