Why Map does not work for GString in Groovy?

前端 未结 2 742
庸人自扰
庸人自扰 2020-12-07 01:53

With the following snippet I cannot retrieve gString from a map:

def contents = \"contents\"
def gString = \"$contents\"

def map = [(gString):         


        
2条回答
  •  执笔经年
    2020-12-07 02:47

    There's nothing wrong with Groovy. A GString is not a String. It is mutable and as such should never be used as a key in a map (like any other mutable object in Java).

    Learn more about this in the docs: http://docs.groovy-lang.org/latest/html/documentation/index.html#_gstring_and_string_hashcodes

提交回复
热议问题