Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.0.0-alpha-2, 2.4.15, 2.5.0
-
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)
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:
[Static type checking] - Cannot assign value of type java.lang.String to variable of type ?
Scenario to reproduce:
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()
Using the put method works just fine:
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()