string concatenation in Groovy seems inconvenient
My goal is to write this:
println "this should be 3: ($1+2)" //this is invalid groovy, it won't run
Yet this is valid in ruby. Is there a way I can put statements that will eval inside a string or must I use complete variabl开发者_开发知识库es names? I am basically looking for the Ruby equivalent of:
puts "this shoud be 3: #{1+2}" #this is valid ruby
This is what you need
println "this should be 3: ${1+2}"
If the code being evaluated is a variable name or a GPath expression you can omit the curly braces, e.g.
def foo = "bar"
println "The value is $foo"
But if you want to be on the safe side, always put the code inside ${}
精彩评论