|
Groovy example source code file (GuillaumesMapBug.groovy)
The Groovy GuillaumesMapBug.groovy source codepackage 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: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 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.