Cleaning up the Expando class in Groovy

I want to replace a Groovy object Map

that I use heavily for various data with a class object Expando

. However, since the object is currently being Map

reused multiple times in my code, I also want to clear all data associated with it.

So now I just call map.clear()

to remove all data from the object Map

. Is there a similar approach for a class Expando

in Groovy?

+3


source to share


1 answer


You can clear the instance Expando

by calling .properties.clear()

. Try the following in Groovy Console



def ex = new Expando()

ex.foo = 'fooVal'
ex.bar = 'barVal'

assert 2 == ex.properties.size()

ex.properties.clear()
assert 0 == ex.properties.size()

      

+5


source







All Articles