This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_2_5_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 6f31bf4560be637e5958db8733430f0e88791bc3 Author: Paul King <pa...@asert.com.au> AuthorDate: Thu May 21 16:44:28 2020 +1000 additional doco for dynamic method selection --- src/spec/doc/core-object-orientation.adoc | 7 +++++++ src/spec/test/objectorientation/MethodsTest.groovy | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/spec/doc/core-object-orientation.adoc b/src/spec/doc/core-object-orientation.adoc index 8961ae6..65a3455 100644 --- a/src/spec/doc/core-object-orientation.adoc +++ b/src/spec/doc/core-object-orientation.adoc @@ -523,6 +523,13 @@ a| ---- include::{projectdir}/src/spec/test/objectorientation/MethodsTest.groovy[tags=multi_method_distance_interface_over_super,indent=0] ---- + +| For a primitive argument type, a declared parameter type which is the same or slightly larger is preferred. +a| +[source,groovy] +---- +include::{projectdir}/src/spec/test/objectorientation/MethodsTest.groovy[tags=primitive_larger_over_smaller,indent=0] +---- |==== In the case where two variants have exactly the same distance, this is deemed ambiguous and will cause a runtime exception: diff --git a/src/spec/test/objectorientation/MethodsTest.groovy b/src/spec/test/objectorientation/MethodsTest.groovy index 0223e76..2f4a691 100644 --- a/src/spec/test/objectorientation/MethodsTest.groovy +++ b/src/spec/test/objectorientation/MethodsTest.groovy @@ -239,6 +239,16 @@ class MethodsTest extends GroovyTestCase { ''' assertScript ''' + // tag::primitive_larger_over_smaller[] + def method(Long l) { 'Long' } + def method(Short s) { 'Short' } + def method(BigInteger bi) { 'BigInteger' } + + assert method(35) == 'Long' + // end::primitive_larger_over_smaller[] + ''' + + assertScript ''' // tag::multi_method_distance_interface_over_super[] interface I {} class Base {}