|
Groovy example source code file (MethodDispatchBug.groovy)
The Groovy MethodDispatchBug.groovy source codepackage groovy.bugs class MethodDispatchBug extends GroovyTestCase { def doit(Object parameter1, Object parameter2) { "OO" } def doit(Boolean parameter1, Object parameter2) { "BO" } def doit(Object parameter1, Boolean parameter2) { "OB" } def doit(Boolean parameter1, Boolean parameter2) { "BB" } def testBug() { def o = this; assert "BB" == o.doit(true, true); assert "BO" == o.doit(true, 9); assert "OB" == o.doit(9, true); assert "OO" == o.doit(9, 9); } def methodWithDefaults(a,b,c=1000) { a+b+c } void testListExpansion() { // there was a bug discovered while looking at GROOVY-1803 // a list expansion was cached like // methodWithDefaults(List) -> methodWithDefaults(Object,Object,Object) // but this cached version can't handle lists with an arbitrary length // of parameters, resulting in the second call here to fail assert methodWithDefaults([1,10,100]) == 111 assert methodWithDefaults([1,10]) == 1011 } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy MethodDispatchBug.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.