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

Groovy example source code file (VariablePrecedence.groovy)

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

groovytestcase, groovytestcase, variablefoo, variablefoo, varibleprecedence, varibleprecedence

The Groovy VariablePrecedence.groovy source code

package groovy.bugs

/**
 * @author John Wilson
 * @version $Revision: 4996 $
 */
class VariblePrecedence extends GroovyTestCase {
    
    void testVariablePrecedence() {
 
        assertScript( """
            class VariableFoo {
                def x = 100
                def y = 93
                def c = {x -> assert x == 1; assert y == 93; }

                static void main(args) {
                    def vfoo = new VariableFoo()
                    vfoo.c.call(1)

                    def z = 874;
                    1.times { assert vfoo.x == 100; assert z == 874; z = 39; }
                    assert z == 39;

                    vfoo.local();
                }

                void local() {
                    c.call(1);

                    def z = 874;
                    1.times { assert x == 100; assert z == 874; z = 39; }
                    assert z == 39;
                }
            }

        """ );

    }


/*
 * CURRENTLY BROKEN.  Variable scoping needs an overhaul to * fix it.
 */
    void testVariablePrecedenceInScript_FAILS() { if (notYetImplemented()) return
        assertScript( """
            c = { x -> assert x == 1; assert y == 93; }
            x = 100;
            y = 93;

            c.call(1);
        """);
    }

}

Other Groovy examples (source code examples)

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

new blog posts

 

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