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

Anonymous inner class believes protected method in parent's superclass returns Object

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 2.4.8
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      The below will execute the constructor on `Other` that takes an `Object`, even though `getName()` returns a `String`.

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Parent {
          protected String getName() {
              "sally"
          }
      }
      
      @CompileStatic
      class Child extends Parent {
      
          Inner doSomething() {
              return new Inner() {
                  void go() {
                      new Other(name)
                  }
              }
          }
      
      }
      
      @CompileStatic
      class Other {
          Other(Object object) {
              println "called with other"
          }
          Other(String string) {
              println "called with string"
          }
      }
      
      @CompileStatic
      abstract class Inner {
          abstract void go()
      }
      
      Inner inner = new Child().doSomething()
      inner.go()
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                Schlogen James Kleeh
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: