Thursday, October 29, 2009

What is the difference Between if(null == myVariable) and if(myVariable == null)


null check

Putting equality comparisons back-to-front issomething that is usually done to avoid accidentally doing anassignment, by mis-typing "=" where you meant "==". By putting theconstant (e.g. null) first, you make this mis-typing cause acompilation error, which is good, because it alerts you earlier to yourmistake. It is more important in C and C++ than Java, because themis-typed expression is more likely to be legal in C/C++ than in Java.

Having decided to do equality tests back-to-front, some people decideto do all tests back-to-front, for consistency. Dunno if I agree withthat.

Stumble
Delicious
Technorati
Twitter

0 Comments:

Post a Comment