[英]How to escape - (hyphen) using the groovy language
I am trying to declare a variable that requires hyphen as part of the design spec.我正在尝试声明一个需要连字符作为设计规范一部分的变量。
def user-svc = "accounts"
However, i am getting this error -但是,我收到此错误 -
https://www.tutorialspoint.com/execute_groovy_online.php https://www.tutorialspoint.com/execute_groovy_online.php
$groovy main.groovy
Hello world
Caught: groovy.lang.MissingPropertyException: No such property: user for class: main
groovy.lang.MissingPropertyException: No such property: user for class: main
at main.run(main.groovy:3)
Local variable names must be normal groovy identifiers , which doesn't include the hyphen.局部变量名必须是普通的常规标识符,不包括连字符。
Though any object property name can consist of arbitrary characters, when using quoted identifiers or subscript operator:尽管任何对象属性名称都可以由任意字符组成,但在使用带引号的标识符或下标运算符时:
def m = [:]
m.'user-svc' = "accounts"
println m.'user-svc'
println m['user-svc']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.