?
-
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?
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?