[
https://issues.apache.org/jira/browse/GROOVY-9617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17160059#comment-17160059
]
Eric Milles commented on GROOVY-9617:
-------------------------------------
If you want the same behavior in the short term, you can cast the key to
Object. This will force selection of {{putAt(Map,Object,...)}}.
> 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
> Priority: Minor
>
> 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)