This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 0d0a894  additional doco for dynamic method selection
0d0a894 is described below

commit 0d0a89415d58a9676529b3562f1e49415d3f81a6
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 ffb6ba3..95820d1 100644
--- a/src/spec/doc/core-object-orientation.adoc
+++ b/src/spec/doc/core-object-orientation.adoc
@@ -529,6 +529,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 12f08fd..4b8cb91 100644
--- a/src/spec/test/objectorientation/MethodsTest.groovy
+++ b/src/spec/test/objectorientation/MethodsTest.groovy
@@ -241,6 +241,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 {}

Reply via email to