[ https://issues.apache.org/jira/browse/GROOVY-8652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-8652: -------------------------------- Fix Version/s: 2.5.16 > Putting key on generic Map fails when using CompileStatic > --------------------------------------------------------- > > Key: GROOVY-8652 > URL: https://issues.apache.org/jira/browse/GROOVY-8652 > Project: Groovy > Issue Type: Bug > Components: Static compilation > Affects Versions: 3.0.0-alpha-2, 2.4.15, 2.5.0 > Environment: Elementary OS Freya 0.3.2 > java version "1.8.0_121" > Java(TM) SE Runtime Environment (build 1.8.0_121-b13) > Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) > Reporter: Cleydson José de Figueiredo Júnior > Assignee: Eric Milles > Priority: Minor > Labels: compilestatic > Fix For: 4.0.0-beta-1, 3.0.9, 2.5.16 > > > I'm trying to use Groovy's short hand way to put a new key value to an > encapsulated Map. But the compilation fails with: > > {code:java} > [Static type checking] - Cannot assign value of type java.lang.String to > variable of type ? > {code} > > Scenario to reproduce: > {code:java} > import groovy.transform.CompileStatic > @CompileStatic > class MapHolder { > private Map<?, ?> map = [:] > Map<?, ?> getMap() { > return map > } > } > @CompileStatic > static setMapValue() { > MapHolder mapHolder = new MapHolder() > mapHolder.map.key = 'value' > } > setMapValue() > {code} > Using the *put* method works just fine: > {code:java} > import groovy.transform.CompileStatic > @CompileStatic > class MapHolder { > private Map<?, ?> map = [:] > Map<?, ?> getMap() { > return map > } > } > @CompileStatic > static setMapValue() { > MapHolder mapHolder = new MapHolder() > mapHolder.put('key', 'value') > } > setMapValue() > {code} > -- This message was sent by Atlassian Jira (v8.20.1#820001)