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

Access to constant fields in classes implementing constant interfaces erroneously forbidden in @CompileStatic code

    XMLWordPrintableJSON

Details

    Description

      Compilation of the following files:

      MyConstants.java
      public interface MyConstants  {
          public static final String CONSTANT_1 = "this is constant 1";
      }
      
      MyClass.java
      public class MyClass implements MyConstants {
      }
      
      Program.groovy
      @groovy.transform.CompileStatic
      class Program {
          public static void main(String[] args) {
              println MyClass.CONSTANT_1
          }
      }
      

      ends with error:

      Error:(4, 17) Groovyc: Access to MyClass#CONSTANT_1 is forbidden
      

      For example, the error makes it difficult and counterintuitive to access BaseColumns members via any of content provider contract classes (like ContactsContract) - you need to refer to the interface directly.

      Attachments

        Activity

          People

            melix Cédric Champeau
            jnykiel Janusz Nykiel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: