|
Groovy example source code file (MethodDispatchBug.groovy)
The Groovy MethodDispatchBug.groovy source code
package 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: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.