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

Static type checking

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 2.4.8
    • Component/s: Static compilation
    • Labels:
      None

      Description

      I have a problem running this code:

      Test.groovy
      import groovy.transform.CompileStatic 
      import java.util.function.Function 
        
      @CompileStatic 
      class Test { 
              static void main(String[] args) { 
                     // this code fails 
                      Function<Integer, Integer> fct = { Integer n -> 
                              -n 
                      } 
        
                      // this one works but it is too verbose 
                      // Function<Integer, Integer> fct = ({ Integer n -> 
                      // -n 
                      // } as Function<Integer, Integer>) 
        
                      println fct.apply(10) 
              } 
      } 
      

      Error:

      Test.groovy: 9: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.function.Function <java.lang.Integer, groovy.lang.Closure> to: java.util.function.Function <Integer, Integer>
      @ line 9, column 36.
      Function<Integer, Integer> fct = { Integer n ->
      ^
      1 error

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                cazacugmihai Cazacu Mihai
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: