[
https://issues.apache.org/jira/browse/GROOVY-4483?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Wagenleitner closed GROOVY-4483.
-------------------------------------
Resolution: Fixed
Fix Version/s: 1.8.7
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.
> Constants resolving doesn't work in map.put()
> ---------------------------------------------
>
> Key: GROOVY-4483
> URL: https://issues.apache.org/jira/browse/GROOVY-4483
> Project: Groovy
> Issue Type: Sub-task
> Components: Compiler
> Affects Versions: 1.7.3, 1.7.4, 1.7.5
> Environment: Groovy 1.7.3
> Reporter: Erik Pragt
> Fix For: 1.8.7
>
>
> I have the following code which doesn't work:
> {noformat}
> import static Constants.*
> class Constants {
> static final String NAME = "name"
> }
> def map = [:]
> if(!map[NAME]) { // <------ this succeeds...
> map[NAME] = "erik" // <------ this fails!
> }
> println map
> {noformat}
> However, the following does work:
> {noformat}
> 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...
> }
> {noformat}
> This can also be solved by prefixing the NAME constant with the class
> (Constants.NAME)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)