Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11276

Generics error in method resolution

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.20, 4.0.17
    • 4.0.18, 3.0.21
    • Static Type Checker
    • None

    Description

      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.

      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())
            }
          }
        }
      }
      
      [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())
              ^
      

      Update: Using a type witness as Collections.<String> emptyList() works.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: