How to determine if a variable exists from Groovy code running in the Scripting Engine?
The variable was placed ScriptEngine put method
In groovy.lang.Script, there is a public Binding getBinding() method. See Also groovy.lang.Binding using the public boolean hasVariable(String name) method.
public Binding getBinding()
public boolean hasVariable(String name)
This way you can just check for the existence of a variable, e.g.
if (binding.hasVariable('superVariable')) { // your code here }
The variables introduced by the Scripting Engine are stored within binding.variables , so you can, for example, check a variable called xx :
binding.variables
xx
if (binding.variables["xx"]) ...
// Example usage: defaultIfInexistent({myVar}, "default") def defaultIfInexistent(varNameExpr, defaultValue) { try { varNameExpr() } catch (exc) { defaultValue } }
Source: https://habr.com/ru/post/1264734/More articles:Extract path from full file name in VBA - vbaAttempting to fix AVAudioPlayer delay on initial use - ios4Position Calibration - rCSS Resource Lock - javascriptDoes the sound causing the game lag behind in a fast game with a set of sprites? - swiftAn existing high order function for this algorithm? - collectionsHow to create a series of numbers with unique numbers in C? - cTypescript interface with index and other properties - typescriptWhat is the best way to encrypt NSURLCache? - iosWhy is window.navigator.plugins undefined? - seleniumAll Articles