Groovy: How to set a property in setProperty () and avoid infinite recursion?

I am trying to implement a domain class that records when a property value has been changed, but my call setProperty()leads to infinite recursion when setting the actual value.

Here's what it looks like right now:

void setProperty(String name, value)
{
    if(name == "modified")
    {
        this.modified = value
        return
    }
    else
    {
        if(this[name]==value)
        {
            return
        }
        this.modified = true
        this[name]=value
    }
}

So, how can I access a property with its name without causing a recursive call setProperty()? Or is there another way to achieve my goal?

+5
source share
1 answer

All Articles