You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/25 14:04:00 UTC
[jira] [Assigned] (GROOVY-8652) Putting key on generic Map fails
when using CompileStatic
[ https://issues.apache.org/jira/browse/GROOVY-8652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-8652:
-----------------------------------
Assignee: Eric Milles
> 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
>
> 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.3.4#803005)