如何确定在脚本引擎中运行的 Groovy 代码中是否存在变量?
变量由 ScriptEngine's put method 放置
最佳答案
在 groovy.lang.Script 中有一个方法 public Binding getBinding()
。和 groovy.lang.Binding有方法 public boolean hasVariable(String name)
。
因此您可以简单地检查变量是否存在,例如:
if (binding.hasVariable('superVariable')) {
// your code here
}
关于java - 如何确定在脚本引擎中运行的 Groovy 代码中是否存在变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42465028/