Skip to content

Instantly share code, notes, and snippets.

@joeRinehart
Last active December 17, 2015 22:49
Show Gist options
  • Save joeRinehart/5684746 to your computer and use it in GitHub Desktop.
Save joeRinehart/5684746 to your computer and use it in GitHub Desktop.
def someKindaClassProcessorMap = [
(String) : new StringProcessor(),
(Date) : new DateProcessor()
]
def someMap = [
("${someVariableContainingTheKeyName}") : "someValue"
]
@osscontributor
Copy link

You can simplify that to something like this:

def someMap = [
  (someVariableContainingTheKeyName) : "someValue"
]

There is no need to wrap the key value in a GroovyString. Surrounding any expression with parens in that spot will cause the expression to be evaluated and whatever the expression evaluates to will be the key. If you leave the parens off, the literal "someVariableContainingTheKeyName" will be the key, which is not what you want in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment