Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
现在,当我尝试在 Groovy 中评估一段代码时,我必须执行以下操作:
new GroovyShell(new Binding([var1:var1])).evaluate(line)
当您定义了很多变量时,这可能会非常讨厌。有没有更好的方法来做到这一点?是否有类似 Python 的locals东西,或者类似的东西列出了所有声明的变量?
locals
我还没有测试过这个......但它可能会起作用:
new GroovyShell(this.binding).evaluate(line)
或这个:
new GroovyShell(new Binding(this.binding.variables)).evaluate(line)