举例子看吧

 

def map = [:]
map."an identifier with a space and double quotes" = "ALLOWED"
map.'with-dash-signs-and-single-quotes' = "ALLOWED"
assert map."an identifier with a space and double quotes" == "ALLOWED"
assert map.'with-dash-signs-and-single-quotes' == "ALLOWED"

 

单引号,双引号,三个单引号,三个双引号,斜杠,$斜杠 都支持

map.'single quote'
map."double quote"
map.'''triple single quote'''
map."""triple double quote"""
map./slashy string/
map.$/dollar slashy string/$

 

标识符里面还能加变量

def firstname = "Homer"
map."Simpson-${firstname}" = "Homer Simpson"
assert map.'Simpson-Homer' == "Homer Simpson"

 

敲敲看

def map=[:]
map."ddd d"="aaaff"
map.'dddd-z'="aaaff"
map.'''a'''='''b'''
map./s/=/v/
map.$/zz/$=$/zz/$
assert map."ddd d"=="aaaff"
assert map.'dddd-z'=="aaaff"
log.info map

 out :Fri Jan 03 10:32:29 CST 2020: INFO: {ddd d=aaaff, dddd-z=aaaff, a=b, s=v, zz=zz}

 

 

知识从来官网来

http://docs.groovy-lang.org/docs/latest/html/documentation/#_identifiers

相关文章:

  • 2021-11-19
  • 2021-08-19
  • 2021-07-05
  • 2021-10-26
  • 2021-09-21
猜你喜欢
  • 2022-02-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
相关资源
相似解决方案