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

Problem With "this" Inside Of Anonymous Inner Class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.3, 2.4.1
    • 2.5.7, 3.0.0
    • None
    • None

    Description

      If an anonymous inner class is defined inside of a static method, "this" does not reference what it should:

      Demo.groovy
      class Demo {
          static void main(arg) {
              def r = new Runnable() {
                  void run() {
                      if(this instanceof Runnable) {
                          println 'Yep'
                      } else {
                          println 'Nope'
                      }
                  }
              }
              r.run()
          }
      }
      
      $ groovy Demo
      Nope
      

      2.3.3 is the only version I have tested this with.

      Attachments

        Activity

          People

            emilles Eric Milles
            brownj Jeff Brown
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: