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

Lambda with command method call fails with cast exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0-alpha-3
    • 4.0.0-beta-2
    • None
    • None

    Description

      Consider the following:

      import java.util.function.*
      
      Supplier<String> s = () -> 'hello'
      print s.get()
      
      Consumer<String> c = x -> print x;
      c.accept(' ')
      
      Function<Integer, String> f = (Integer i) -> { 'world' }
      print f(42)
      

      This script prints "hello world" under Groovy 3 but fails at runtime under Groovy 4 with exception:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'interface java.util.function.Consumer' with class 'java.lang.Class' to class 'java.util.function.Consumer'
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: