You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/09 16:57:00 UTC
[jira] [Created] (GROOVY-10653) SC: support extension or variadic method reference with instance expression
Eric Milles created GROOVY-10653:
------------------------------------
Summary: SC: support extension or variadic method reference with instance expression
Key: GROOVY-10653
URL: https://issues.apache.org/jira/browse/GROOVY-10653
Project: Groovy
Issue Type: Improvement
Components: Static compilation
Reporter: Eric Milles
Assignee: Eric Milles
Case #1:
{code:groovy}
@CompileStatic
int test(CharSequence chars) {
IntSupplier sizing = chars::size // from StringGroovyMethods
return sizing.getAsInt()
}
{code}
"size" is extension method (static method from another class). Currently this errors at runtime: Incorrect number of parameters for static method invokeStatic org.codehaus.groovy.runtime.StringGroovyMethods.size:(CharSequence)int; 0 captured parameters, 0 functional interface method parameters, 1 implementation parameters
Case #2:
{code:groovy}
class C {
List m(... args) {
[this,*args]
}
}
@CompileStatic
void test(C c) {
BiFunction<Integer, Integer, List> two = c::m
def list = two.apply(1,2)
assert list.size() == 3
assert list[0] == c
assert list[1] == 1
assert list[2] == 2
}
test(new C())
{code}
"m" requires an adapter method (in the enclosing script class), which results in a static method in a different class from that of "c".
--
This message was sent by Atlassian Jira
(v8.20.7#820007)