使用“$”在Groovy [英] Using "$" in Groovy

查看:81
本文介绍了使用“$”在Groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看{}用于闭包,然后我相信当$放在大括号的前面时,它只是在一个字符串内进行变量替换。我找不到有关如何在引用中工作的文档...很难在其上进行搜索,并且Groovy String文档缺乏介绍。您能否指点我的文档和/或解释Groovy中的$操作符 - 它如何使用? Grails在Groovy之外是否扩展它?

解决方案

在GString(groovy字符串)中,任何有效的Groovy表达式都可以包含在$ {...}包括方法调用等。

这在关注页面


I see { } are used for closures, and then I believe when a $ is put in front of braces, it is simply doing a variable substitution within a string. I can't find the documentation on how the $ works in the reference ... hard to search on it unfortunately, and the Groovy String documentation is lacking in introducing this. Can you please point me to the documentation and/or explain the "$" operator in Groovy -- how all it can be used? Does Grails extend it at all beyond Groovy?

解决方案

In a GString (groovy string), any valid Groovy expression can be enclosed in the ${...} including method calls etc.

This is detailed in the following page.

这篇关于使用“$”在Groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆