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

Groovy allows a Java class to inherit static methods from its interface

    XMLWordPrintableJSON

Details

    Description

      In the following situation Java doesn't compile (as per JLS8 - 8.4.8 Inheritance, Overriding, and Hiding):

      interface Foo {
        static void foo() {
          System.out.println("static void foo() called");
        }
      }
      
      class Bar implements Foo { }
      
      public class FooBarTest {
          public static void main(String[] args) {
              Bar.foo();
          }
      }
      
      $ javac FooBarTest.java
      FooBarTest.java:3: error: cannot find symbol
              Bar.foo();
                 ^
        symbol:   method foo()
        location: class Bar
      1 error
      

      But Groovy does compile, both dynamic and @CompileStatic and we get static void foo() called in the output

      Just in case, here is a snippet from JLS8:
      8.4.8 Inheritance, Overriding, and Hiding
      A class C inherits from its direct superclass all concrete methods m (both static and instance) of the superclass for which all of the following are true:
      ...
      A class does not inherit static methods from its superinterfaces.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              DmitryKh Dmitry Khamitov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: