[
https://issues.apache.org/jira/browse/GROOVY-6638?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17601829#comment-17601829
]
Eric Milles commented on GROOVY-6638:
-------------------------------------
Since no type arguments are provided to the declaration -- "Map map = [a:1]" --
the type checker tries to work out the type arguments from the RHS -- String
and Integer in this case. If you need the value type to be Integer or Number
or Object or whatever, you need to explicitly specify that: "Map<String,Object>
map = ...".
> STC: flow typing problem with java.util.Map generics parameter types
> --------------------------------------------------------------------
>
> Key: GROOVY-6638
> URL: https://issues.apache.org/jira/browse/GROOVY-6638
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.2.2, 2.3.0, 2.4.0-rc-1, 2.4.1
> Reporter: Lari Hotari
> Assignee: Eric Milles
> Priority: Major
>
> I'm facing flow typing problems with java.util.Map variables.
> This code example:
> {code}
> @groovy.transform.TypeChecked
> def mapExample() {
> Map map = [a: 1]
> map.b = '2'
> map
> }
> {code}
> fails with error:
> {code}
> 1 compilation error:
> [Static type checking] - Cannot assign value of type java.lang.String to
> variable of type java.lang.Integer
> at line: 4, column: 13
> {code}
> I'd assume that this would be the expected behaviour if the variable was
> defined with "def map" instead of "Map map".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)