Groovy多行string有什么问题?
Groovy脚本产生了一个错误:
def a = "test" + "test" + "test" 错误:
 No signature of method: java.lang.String.positive() is applicable for argument types: () values: [] 
虽然这个脚本工作正常:
 def a = new String( "test" + "test" + "test" ) 
为什么?
 由于groovy没有EOL标记(比如; ),所以如果你把操作符放在下面一行,就会感到困惑 
这将工作,而不是:
 def a = "test" + "test" + "test" 
因为Groovyparsing器知道期望在下面的行上
  Groovy把你的原始定义看成是三个单独的陈述。 第一个把test分配给a ,第二个"test"正确的(这是失败的地方) 
 使用new String构造函数方法,Groovyparsing器仍然在构造函数中(因为大括号尚未closures),所以它可以在逻辑上将三条线连接成一条语句 
对于真正的多行string,您也可以使用三重引号:
 def a = """test test test""" 
将在三行上创build一个testingstring
另外,你可以通过以下方式使它更整洁:
 def a = """test |test |test""".stripMargin() 
  stripMargin方法将修剪每行的左边(包括| char) 
 您可以告诉Groovy语句应该通过添加一对括号( ... )结束行, 
 def a = ("test" + "test" + "test") 
 第二个选项是在每行的末尾使用反斜杠\ : 
 def a = "test" \ + "test" \ + "test" 
FWIW,这与Python多行语句的工作方式相同。
 类似于stripMargin() ,你也可以使用stripIndent()之类的 
 def a = """\ test test test""".stripIndent() 
因为
具有最less数量的前导空格的行确定要删除的数字。
 您还需要缩进第一个“testing”,而不是直接放在“inital """之后(“ \确保多行string不以换行符开头)。