Possible Duplicate:
Null check in Java
I’m just wondering what’s the difference between
if (null == something) {...}
and
if (something == null) {...}
assuming that in both cases something is the same object. Presumably, there should be non, except for readability of the code.
There is no difference.
The idea of putting the constant first helps guard against accidental assignment in the condition. For example in some languages it is valid to say:
i is assigned and the condition is true. If you didn’t mean to do this, there is no compiler error and it can be difficult to find.
If you instead always put the constant first:
Then the day you accidentally do:
A compiler error will alert you immediately that you are attempting to assign to a constant.