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

When creating a map, the key cannot reference to a variable?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0-JSR-4
    • 1.0-JSR-6
    • None
    • None

    Description

      Let's say I evaluate the following:
      key = "actualKey"
      map = [key:"value"]
      print map

      The result will be:

      {key=value}

      . What I would like to get is

      {actualKey=value}

      Is this a bug or an intended feature? Basically the key of a map is always interpreted as a string - even if it matches an actual string variable in the scope.

      I can use the following workaround, but I feel it's a bit ugly. Are there any better alternatives available?
      key = "actualKey"
      map = ["$key":"value"]
      print map

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            mhalttu Markus Halttunen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: