You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Laurent Martelli (Jira)" <ji...@apache.org> on 2020/07/03 08:22:00 UTC
[jira] [Created] (GROOVY-9617) map.put(key,value) and map[key] =
value differ is key is a GString
Laurent Martelli created GROOVY-9617:
----------------------------------------
Summary: map.put(key,value) and map[key] = value differ is key is a GString
Key: GROOVY-9617
URL: https://issues.apache.org/jira/browse/GROOVY-9617
Project: Groovy
Issue Type: Bug
Affects Versions: 2.5.10
Reporter: Laurent Martelli
The subscript operator of Map transform {{GString}} keys to {{String. }}But {{put()}} does not. This is incoherent.
{code:java}
class App {
static void main(String[] args) {
println("subscript works: "+subscriptWorks())
println("put works: "+putWorks())
}
static def subscriptWorks() {
def map = [:]
def x = "toto"
def key = "$x"
map[key] = "value"
return map.containsKey(key)
}
static def putWorks() {
def map = [:]
def x = "toto"
def key = "$x"
map.put(key,"value")
return map.containsKey(key)
}
}
{code}
Outputs this :
{code:java}
subscript works: false
subscript works: true
{code}
It would be better to either cast all key parameters of all methods from GString to String or none. The current behaviour is very confusing.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)