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

Compile static to support streams

    XMLWordPrintableJSON

Details

    Description

      The following code

      import groovy.transform.CompileStatic
      
      import static java.util.stream.Collectors.toList
      
      @CompileStatic
      class Test {
          static void main(String[] args) {
              List<String> tables = ['a', 'b']
              println tables.stream().filter { tableName -> tableName.contains('a') }.collect(toList())
          }
      }
      

      fails with the error:
      Error:(9, 55) Groovyc: [Static type checking] - Cannot find matching method java.lang.Object#contains(java.lang.String). Please check if the declared type is right and if the method exists.

      But works fine with compile dynamic.
      It would be great if CompileStatic get all required types from the steam (type info should be there, Java can handle similar code)

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            ichulovskyi Iurii
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: