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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.7-rc-1
    • 1.7-rc-2
    • Compiler
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: