Checking old value with new value before setting.

?

-

Should one bother checking whether a current value differs from the new
value before setting the value to the new value?

public void setString(String string) {
if (this.string != string) {
this.string = string;
}
}

I've seen such cases in Swing where firePropertyChange is involved so
that it only when the value truly changes should firePropertyChange be
called. I've also seen cases, also in Swing, where they do not do the
checking and still call firePropertyChange. Since both are from Swing,
I couldn't make up my mind on which way to abide by.

If the parameter is non primitive, then how can i check for its equality?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top