Paul King created GROOVY-12781:
----------------------------------
Summary: A method reference to overloaded methods selects by
declared parameter types under @CompileStatic and by argument types under
@TypeChecked
Key: GROOVY-12781
URL: https://issues.apache.org/jira/browse/GROOVY-12781
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Paul King
{code:groovy}
import java.util.function.Function
@groovy.transform.CompileStatic
class C {
static String pick(Object o) { 'Object' }
static String pick(String s) { 'String' }
static main(args) {
Function<Object, String> f = C::pick
println f.apply('x')
}
}
{code}
With 5.1.3 and 6.0.0, this prints {{Object}} under {{@CompileStatic}}, and
{{String}} under {{@TypeChecked}} and as dynamic code. Java prints {{Object}}.
Under {{@CompileStatic}} the method is selected when the reference is compiled,
by the parameter types of the functional interface, as in Java. Otherwise the
reference is a method closure that selects the method by the argument at each
call. Each is consistent on its own, but the same source gives different
results with the two annotations.
This may be intended. If so, the difference could be stated in the
documentation of method references and in the list of differences between
{{@TypeChecked}} and {{@CompileStatic}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)