Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

groovy beginner- how to remove a variable from memory in groovy shell

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.

like image 635
Arvind Avatar asked May 29 '12 10:05

Arvind


People also ask

How do I pass a variable 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.

How do you clear a variable value in Java?

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.

What does [:] mean in Groovy?

[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]

What is ${} in Groovy?

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 ${} .


1 Answers

I believe you can do:

binding.variables.remove 'varname'

Or, if you want to remove all variables, then

purge variables

should work as well

like image 197
tim_yates Avatar answered Sep 22 '22 00:09

tim_yates