[
https://issues.apache.org/jira/browse/GROOVY-9617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17601320#comment-17601320
]
Eric Milles commented on GROOVY-9617:
-------------------------------------
GROOVY-6668, GROOVY-8212 and GROOVY-9529 actually request that this behavior be
extended to static type checking and static compilation.
> 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
> Assignee: Eric Milles
> Priority: Minor
>
> The subscript operator of Map transform {{GString}} keys to {{String}}. But
> {{put()}} does not. This is inconsistent.
>
> {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.20.10#820010)