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.

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            hans_d Hans Dockter

            Dates

              Created:
              Updated:

              Slack

                Issue deployment