Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 什么';${foo}和#{bar}之间的区别是什么?_Groovy - Fatal编程技术网

Groovy 什么';${foo}和#{bar}之间的区别是什么?

Groovy 什么';${foo}和#{bar}之间的区别是什么?,groovy,Groovy,字符串占位符中的${foo}和{bar}之间有什么区别?{}不是一个简单的groovy构造,它不会被计算 def foo = 1 def bar = 2 println "${foo} and #{bar}" 返回 1 and #{bar} 也许它与Ruby和/或Coffeescript自己的字符串插值混合在一起 红宝石: : Groovy使用${}表示法,需要使用双引号或三重双引号声明字符串: groovy:000> a = "bar" ===> bar groovy:0

字符串占位符中的
${foo}
{bar}
之间有什么区别?

{}
不是一个简单的groovy构造,它不会被计算

def foo = 1
def bar = 2

println "${foo} and #{bar}"
返回

 1 and #{bar}

也许它与Ruby和/或Coffeescript自己的字符串插值混合在一起

红宝石:

:


Groovy使用
${}
表示法,需要使用双引号或三重双引号声明字符串:

groovy:000> a = "bar"
===> bar
groovy:000> """to the $a"""
===> to the bar
groovy:000> "to the ${a}"
===> to the bar

或是一根粗线,或是一美元粗线。
a = "coffee"
alert "i'd love some #{a}"
groovy:000> a = "bar"
===> bar
groovy:000> """to the $a"""
===> to the bar
groovy:000> "to the ${a}"
===> to the bar