Groovy 引号标识符

举例子看吧

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

原文地址:https://www.cnblogs.com/baxianhua/p/12143692.html