Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.3, 1.7.4, 1.7.5
    • 1.8.7
    • Compiler
    • None
    • Groovy 1.7.3

    Description

      I have the following code which doesn't work:

      import static Constants.*
      
      class Constants {
        static final String NAME = "name"
      }
      
      def map = [:]
      if(!map[NAME]) {               // <------ this succeeds...
        map[NAME] = "erik"          // <------ this fails!
      }
      
      println map
      

      However, the following does work:

      import static Constants.*
      
      class Constants {
        public static final String NAME = "name"         // <---- mind the public!
      }
      
      def map = [:]
      if(!map[NAME]) {             // <------ this succeeds...
        map[NAME] = "erik"          // <------ and this also succeeds...
      }
      

      This can also be solved by prefixing the NAME constant with the class (Constants.NAME)

      Attachments

        Activity

          Appears this was fixed in 1.8, the first code sample runs successfully in 1.8.9 (and current versions) and prints the expected output.

          jwagenleitner John Wagenleitner added a comment - Appears this was fixed in 1.8, the first code sample runs successfully in 1.8.9 (and current versions) and prints the expected output.

          People

            Unassigned Unassigned
            bodiam Erik Pragt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: