[
https://issues.apache.org/jira/browse/GROOVY-8652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Cleydson José de Figueiredo Júnior updated GROOVY-8652:
-------------------------------------------------------
Description:
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 method *put* works just fine.
was:
I'm trying to use Groovy's short hand way to put a new key value to a
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 method *put* works just fine.
> 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
> 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 method *put* works just fine.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)