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/01/27 14:50:01 UTC

[jira] [Updated] (GROOVY-9914) map.collectEntries extension method variant returns Map

     [ https://issues.apache.org/jira/browse/GROOVY-9914?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-9914:
--------------------------------
    Description: 
Consider the following:
{code:groovy}
@groovy.transform.TypeChecked
void test(Map<String,String> one) {
  Map<String,Integer> two = one.collectEntries { k,v ->
    [k: v.hashCode()]
  }
}
{code}

Assignment to "two" produces the following error "[Static type checking] - Incompatible generic argument types. Cannot assign java.util.Map <?, ?> to: java.util.Map <String, Integer>".

The "collectEntries" variant called here returns "Map<?,?>"; all other variants return a parameterized type that is determined by the caller.

  was:
Consider the following:
{code:groovy}
@groovy.transform.TypeChecked
void test(Map<String,String> one) {
  Map<String,Integer> two = one.collectEntries { k,v ->
    [k: v.hashCode()]
  }
}
{code}

Assignment to "two" produces the following error "[Static type checking] - Incompatible generic argument types. Cannot assign java.util.Map <java.lang.Object extends java.lang.Object, java.lang.Object extends java.lang.Object> to: java.util.Map <String, Integer>".

The "collectEntries" variant called here returns "Map<?,?>"; all other variants return a parameterized type that is determined by the caller.


> map.collectEntries extension method variant returns Map<?,?>
> ------------------------------------------------------------
>
>                 Key: GROOVY-9914
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9914
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Minor
>
> Consider the following:
> {code:groovy}
> @groovy.transform.TypeChecked
> void test(Map<String,String> one) {
>   Map<String,Integer> two = one.collectEntries { k,v ->
>     [k: v.hashCode()]
>   }
> }
> {code}
> Assignment to "two" produces the following error "[Static type checking] - Incompatible generic argument types. Cannot assign java.util.Map <?, ?> to: java.util.Map <String, Integer>".
> The "collectEntries" variant called here returns "Map<?,?>"; all other variants return a parameterized type that is determined by the caller.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)