|
Groovy example source code file (GuillaumesMapBug.groovy)
The Groovy GuillaumesMapBug.groovy source code
package groovy.bugs
/**
* @author Guillaume Laforge
* @version $Revision: 4996 $
*/
class GuillaumesMapBug extends GroovyTestCase {
void testBug2() {
def list = [1, 2, 3]
def map = [:]
doLoop(list, map)
assert map[0] == 1
assert map[1] == 2
assert map[2] == 3
}
void doLoop(list, map) {
def i = 0
for (it in list) {
map[i++] = it
}
}
void testBug() {
def list = [1, 2, 3]
def map = [:]
doClosureLoop(list, map)
assert map[0] == 1
assert map[1] == 2
assert map[2] == 3
}
void doClosureLoop(list, map) {
def i = 0
list.each { map[i++] = it }
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy GuillaumesMapBug.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.