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

Cannot call super when overriding an interface default method

    XMLWordPrintableJSON

Details

    Description

      Suppose you have:

      public interface MyInterface {
        default String getFoo() { return "foo"; }
      }
      

      and a Groovy class implementing it:

      @CompileStatic
      class MyClass implements MyInterface {
        @Overridde
        String getFoo() {
          return MyInterface.super.getFoo();
        }
      }
      

      This produces multiple compiler errors, like:

      - Groovy:[Static type checking] - No such property: super for class: java.lang.Class <MyInterface>
      - Groovy:The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes
      

      If I replace it with:

      @CompileStatic
      class MyClass implements MyInterface {
        @Overridde
        String getFoo() {
          return super.getFoo();
        }
      }
      

      I get:

      Groovy:[Static type checking] - Cannot find matching method java.lang.Object#getFoo(). Please check if the declared type is correct and if the method exists
      

      I find no way to properly override a default method while calling the super implementation.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              mauromol Mauro Molinari
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: