You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2024/03/05 01:54:00 UTC

[jira] [Closed] (GROOVY-11276) Generics error in method resolution

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

Paul King closed GROOVY-11276.
------------------------------

> Generics error in method resolution
> -----------------------------------
>
>                 Key: GROOVY-11276
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11276
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.20, 4.0.17
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 4.0.18, 3.0.21
>
>
> There's a chance this is a duplicate of a ticket recently fixed, but it's odd enough (and the message is unclear enough) that I'm reposting it.
> {code}
> Map<String, List<String>> idsForAccounts(Collection<String> persons) {
>   Map<Object, Object> fromGraph = retrieve()
>   // workaround for buggy database implementation follows
>   new HashMap<String, List<String>>().tap { result ->
>     putAll(fromGraph as Map<String, List<String>>)
>     persons.forEach {
>       if (!result.containsKey(it)) {
>         result.put(it, emptyList())
>       }
>     }
>   }
> }
> {code}
> {code}
> [Static type checking] - Cannot find matching method java.util.HashMap#put(java.lang.String, java.util.List<#T>). Please check if the declared type is correct and if the method exists.
>   @ line 73, column 21.
>         result.put(it, emptyList())
>         ^
> {code}
> Update: Using a type witness as {{Collections.<String> emptyList()}} works.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)