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

Improve type inference for method reference

    XMLWordPrintableJSON

Details

    Description

      Compiling this code:

      assert 'Hi'.transform(String::length) * 3 == 6 // transform is JDK12
      

      with type checking gives:

      [Static type checking] - Cannot find matching method java.lang.Object#multiply(int). Please check if the declared type is correct and if the method exists.
      

      We can close as duplicate if this overlaps with an existing issue. It might not be anything to do with method references but an existing limitation in the type checker around supporting generics involving bounded parameters. For reference, the definition of transform is:

      public <R> R transform​(Function<? super String,​? extends R> f)
      

      Attachments

        Activity

          People

            emilles Eric Milles
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: