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

STC: closure/lambda/reference parameter as type witness for SAM type generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.5, 2.5.19, 3.0.13
    • None
    • None

    Description

      Consider the following:

      import java.util.function.*
      import java.util.stream.*
      import groovy.transform.*
      class Named {
        String name
      }
      @TypeChecked
      void test() {
        def c1 = Collectors.groupingBy(Named::getName)
        def c2 = Collectors.groupingBy(Named.&getName)
        def c3 = Collectors.groupingBy{Named named -> named.getName()}
        def c4 = Collectors.groupingBy((Named named) -> named.getName())
      }
      

      In each case, the type inference engine should be able to work out the type of the declared variable as: Collector<Named, ?, Map<String, List<Named>>>

      To do so, the parameter type Named (and return type String) must be mapped onto Function<? super T, ? extends K> of Collectors#groupingBy.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: