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

Extension method support for native method references

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-beta-2
    • None
    • None

    Description

      The following two method reference statements compile and execute successfully with and without @CS (and with CS produce the correct native bytecode):

      assert 'Hi'.transform(String::length) == 2 // transform is JDK12
      assert 'Hi'.transform(StringGroovyMethods::size) == 2
      

      This statement (using the extension method from StringGroovyMethods) works for dynamic Groovy:

      assert 'Hi'.transform(String::size) == 2
      

      But for static Groovy fails compilation with:

      1 compilation error:
      org.codehaus.groovy.syntax.RuntimeParserException: Failed to find the expected method[size(java.lang.String)] in the type[java.lang.String]
      

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m