Skip to content

Commit b8619e8

Browse files
committed
additional doco for dynamic method selection
1 parent 317aeb5 commit b8619e8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/spec/doc/core-object-orientation.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ a|
529529
----
530530
include::{projectdir}/src/spec/test/objectorientation/MethodsTest.groovy[tags=multi_method_distance_interface_over_super,indent=0]
531531
----
532+
533+
| For a primitive argument type, a declared parameter type which is the same or slightly larger is preferred.
534+
a|
535+
[source,groovy]
536+
----
537+
include::{projectdir}/src/spec/test/objectorientation/MethodsTest.groovy[tags=primitive_larger_over_smaller,indent=0]
538+
----
532539
|====
533540
534541
In the case where two variants have exactly the same distance, this is deemed ambiguous and will cause a runtime exception:

src/spec/test/objectorientation/MethodsTest.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ class MethodsTest extends GroovyTestCase {
240240
// end::object_array_over_object[]
241241
'''
242242

243+
assertScript '''
244+
// tag::primitive_larger_over_smaller[]
245+
def method(Long l) { 'Long' }
246+
def method(Short s) { 'Short' }
247+
def method(BigInteger bi) { 'BigInteger' }
248+
249+
assert method(35) == 'Long'
250+
// end::primitive_larger_over_smaller[]
251+
'''
252+
243253
assertScript '''
244254
// tag::multi_method_distance_interface_over_super[]
245255
interface I {}

0 commit comments

Comments
 (0)