home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (MethodDispatchBug.groovy)

This example Groovy source code file (MethodDispatchBug.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

bb, bo, bo, boolean, boolean, groovytestcase, methoddispatchbug, ob, ob, object, object, oo

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:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.