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

intended behaviour change in 1.7rc1? can no longer set final variable in static initializer

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.7-rc-1
    • Fix Version/s: 1.7-rc-2
    • Component/s: Compiler
    • Labels:
      None

      Description

      I'm just checking if this is intended .... as it seems a difference from 1.7beta2 and also a difference from pure java.

      This compiles under javac:

      class A {
      
        static final String foo;
      
        static {
          if (true) {
            foo = "roshan";
          } else {
            foo = "jochen";
          }
        }
      }
      

      and it compiles under 1.7beta2, but under 1.7rc1 I get:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      A.groovy: 7: cannnot access final field or property outside of constructor.
       @ line 7, column 7.
               foo = "roshan";
               ^
      
      A.groovy: 9: cannnot access final field or property outside of constructor.
       @ line 9, column 7.
               foo = "jochen";
               ^
      
      2 errors
      

        Attachments

          Activity

            People

            • Assignee:
              roshandawrani Roshan Dawrani
              Reporter:
              aclement Andy Clement
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: