File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 529
529
----
530
530
include::{projectdir}/src/spec/test/objectorientation/MethodsTest.groovy[tags=multi_method_distance_interface_over_super,indent=0]
531
531
----
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
+ ----
532
539
|====
533
540
534
541
In the case where two variants have exactly the same distance, this is deemed ambiguous and will cause a runtime exception:
Original file line number Diff line number Diff line change @@ -240,6 +240,16 @@ class MethodsTest extends GroovyTestCase {
240
240
// end::object_array_over_object[]
241
241
'''
242
242
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
+
243
253
assertScript '''
244
254
// tag::multi_method_distance_interface_over_super[]
245
255
interface I {}
You can’t perform that action at this time.
0 commit comments