美元符号后的非法字符串身体字符 [英] illegal string body character after dollar sign
问题描述
如果我定义一个groovy变量
pre $ def x =anish $
它会抛出错误,修正是
def x =anish \ $
除了$之外什么是黑名单字符需要反斜杠,是否有Groovy引用列出了保留字符。大多数语言规范都提到了这些细节,但我没有看到Groovy语言 spec (很多TODO评论)。
只需使用单引号:
def x ='anish $'
如果这是不可能的,唯一的这会导致你的问题是 $
,因为这是 GString
使用的模板字符(请参阅GString部分<一个href =http://groovy.codehaus.org/Strings+and+GString =noreferrer>在这个页面上 - 大约下降一半)
显然,反斜杠字符也需要转义,即:
def x ='anish \\ '
if i define a groovy variable
def x = "anish$"
it will throw me error, the fix is
def x = "anish\$"
apart form "$" what are the blacklist characters that needs to be backslash,Is there a Groovy reference that lists the reserved characters. Most "language specifications" mention these details, but I don’t see it in the Groovy language spec (many "TODO" comments).
Just use single quotes:
def x = 'anish$'
If this isn't possible, the only thing that's going to cause you problems is $
, as that is the templating char used by GString
(see the GString section on this page -- about half way down)
Obviously, the backslash char needs escaping as well, ie:
def x = 'anish\\'
这篇关于美元符号后的非法字符串身体字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!