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

Cannot create method reference for print or println

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.13, 4.0.6
    • 3.0.14, 4.0.7
    • Static compilation
    • None

    Description

      Consider the following:

      @groovy.transform.CompileStatic
      void p() {
        java.util.function.Consumer c = this::print
        c.accept('hello world!')
      }
      p()
      

      Throws error "LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting class script, found class java.lang.Object"

      I was trying to print a stream element via "this::println". This fails also with "System.out::println" as well. I had to use closure syntax which works just fine. Lambda throws NPE: "Consumer c = obj -> print(obj)"

      Attachments

        1. screenshot-1.png
          14 kB
          Felix Schnabel

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: