What's the difference between ${foo}
and #{bar}
in string placeholders?
答案 0 :(得分:2)
#{}
is not a plain groovy construct, it's not evaluated.
def foo = 1
def bar = 2
println "${foo} and #{bar}"
returns
1 and #{bar}
答案 1 :(得分:2)
也许它与Ruby和/或Coffeescript自己的字符串插值混合在一起。
红宝石:
irb(main):001:0> a = "foo"
=> "foo"
irb(main):002:0> "this is a #{a}"
=> "this is a foo"
a = "coffee"
alert "i'd love some #{a}"
Groovy使用${}
表示法,字符串需要使用双引号或三重双引号声明:
groovy:000> a = "bar"
===> bar
groovy:000> """to the $a"""
===> to the bar
groovy:000> "to the ${a}"
===> to the bar