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

Groovy example source code file (AmbiguousListOrMethodTest.groovy)

This example Groovy source code file (AmbiguousListOrMethodTest.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

ambiguouslistormethodtest, calling, calling, caught, caught, example, example, groovytestcase, missingpropertyexception, string, worked, worked

The Groovy AmbiguousListOrMethodTest.groovy source code

package groovy.bugs

class AmbiguousListOrMethodTest extends GroovyTestCase {

    void testLocalVariableVersion() {
        def foo = [3, 2, 3]

        def val = foo [0]
        println val
        assert val == 3

    void testUndefinedPropertyVersion() {
        try {
            def val = this.foo [0]
            println val
        catch (MissingPropertyException e) {
            println "Worked! Caught missing property $e"

    void testMethodCallVersion() {
        def val = foo([0])
        println val
        assert val == 1

    def foo(int val) {
        println "Calling foo method with a int param of val"
        println val
        return null

    def foo(List myList) {
        println "Calling foo method with a list param of $myList"
        return myList.size()

    void testCanFindCorrectMethod() {
        def e = new Example()
        assert e["", ""] == 2
        assert e[""] == 1


class Example {
    def getAt(String a, String b) {return 2}
    def getAt(String a) {return 1}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy AmbiguousListOrMethodTest.groovy source code file:

new blog posts


Copyright 1998-2016 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.