地图键是否是Groovy中的对象?

Sac*_*rma 5 java groovy

我是一名Java开发人员,现在正在学习groovy但是groovy正在弄乱我的大脑,我需要帮助的东西,其中的主要内容列在这里:

def map = [inm1:'hello',int2f:'world']
map.keySet().each{
println it.class.name
println "values of Key"+it.charAt(2)
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,inm1int2f是Java中的常规变量,但在groovy中,它们是String Values,而不仅仅是具有String值的变量,它们实际上是String Objects本身.
然而,它们是字符串然后为什么没有单个或双"或"引用.我无法理解这个概念,我只是非常想要你的帮助.
还提供了一些资源来学习groovy,我找到了很多资源,但他们采取像上面提到的太轻松了.

tim*_*tes 15

简单的键会自动转换为Groovy中的Strings,因为它简化了常规的Map创建.

如果要评估变量中的键,则需要将它们放在括号中,即:

Integer inm1 = 10
String  int2f = 'hello'

// Regular map with string keys
assert [ inm1:'hello', int2f:'world' ] == [ 'inm1':'hello', 'int2f':'world' ]

// And evaluated keys in parentheses
assert [ (inm1):'hello', (int2f):'world' ] == [ 10:'hello', 'hello':'world' ]
Run Code Online (Sandbox Code Playgroud)