I could not see any method to remove a variable from memory in Groovy shell... is this possible? How do I do this? I can see methods for doings this in Beanshell and Javascript(Rhino) but not in Groovy.
Variables in Groovy can be defined in two ways − using the native syntax for the data type or the next is by using the def keyword. For variable definitions it is mandatory to either provide a type name explicitly or to use "def" in replacement. This is required by the Groovy parser.
Set clear() method in Java with Examples Set. clear() method is used to remove all the elements from a Set. Using the clear() method only clears all the element from the set and not deletes the set. In other words, we can say that the clear() method is used to only empty an existing Set.
[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]
String interpolation. Any Groovy expression can be interpolated in all string literals, apart from single and triple-single-quoted strings. Interpolation is the act of replacing a placeholder in the string with its value upon evaluation of the string. The placeholder expressions are surrounded by ${} .
I believe you can do:
binding.variables.remove 'varname'
Or, if you want to remove all variables, then
purge variables
should work as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With