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

Groovy example source code file (Groovy1059_Bug.groovy)

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

closure, closure, groovy-1059, groovy1059_bug, groovy1059foo, groovy1059foo, groovytestcase, i, i, method, method, object, todo

The Groovy Groovy1059_Bug.groovy source code

package groovy.bugs

/**
 * TODO: GROOVY-1059
 *
 *    Accessible to a closure attribute of an abject with the operator ".@".
 *    For examples, all of the expressions
 *
 *            object.@closure()
 *            object.@closure.call()
 *            object.@closure.doCall()
 *            (object.@closure)()
 *
 *    have the same meaning.
 *
 * @author  John Wilson
 * @author  Pilho Kim
 */

class Groovy1059_Bug extends GroovyTestCase {

    void testClosureAsAttribute() {
        def x = new Groovy1059Foo()

        println( x.say() )
        println( (x.@say)() )
        println( x.@say() )  // TODO: Groovy-1059 should work
        println( x.@say.call() )
        println( x.@say.doCall() )
        println( x.@say2() )

        assert "I am a Method" == x.say()
        assert "I am a Method" == x.@say2()
        assert "I am a Closure" == (x.@say)()
        assert "I am a Closure" == x.@say()
        assert x.@say() == (x.@say)()
        assert x.@say() == x.@say.call()
        assert x.@say() == x.@say.doCall()
        assert x.@say() != x.say()
        assert x.@say2() == x.say()
    }

}

class Groovy1059Foo {

    def public say = { it -> return "I am a Closure" }
    def public say2 = this.&say

    public Object say() {
       return "I am a Method"
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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