Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
1.0-JSR-2
-
None
-
None
-
Windows XP Service Pack 2, but others have reported having the same issue
Description
The underlying Java Map object uses Equals to determine if two keys are the same. But a java String is not equal to a GString.
Here is an example script and it's output:
def animalType = "dog"
def map = [:]
map.put(animalType, "Spike")
println ("key = $animalType")
println ("animalName = " + map.get("dog")) // 1
println "animalName = " + map.get("$animalType") // 2
println "animalName = " + map.get("${animalType}") // 3
println "animalName = " + map.get(animalType) // 4
C:\groovy>groovy -version
Groovy Version: 1.0-jsr-02 JVM: 1.4.2_06-b03
C:\groovy>groovy test.groovy
key = dog
animalName = Spike
animalName = null
animalName = null
animalName = Spike
Notice the null output for lines 2 and 3.
Attachments
Issue Links
- relates to
-
GROOVY-2330 GString vs String equality in collections
- Closed