Just curious, which code is more effective:
if (myClass.getSomeValue() != myValue) myClass.setSomeValue(myValue);
or simply
myClass.setSomeValue(myValue);
, where getSomeValue() and setSomeValue(...) are simple getter-setter pair? It’s clear, then second will be faster in case of .equals() usage, so we using just !=.
The first will be obviously faster.
Don’t optimize before you know where the bottleneck is. Remember, premature optimization is the root of all evil. Usual bottlenecks are database, network, creating lots of objects. Simply checking a value is not a bottleneck.
BEWARE:
!=andequals()are not the same. Former checks for identity (does a reference point to the same object), the later checks for equality (if two distinct objects have the same value).