On Tue, May 3, 2011 at 4:16 AM, Kevin Wright <kev.lee.wri...@gmail.com>wrote:

> There was a code style which stated null checks should have taken the
>> form of if (null == variable) which coming from Java I said was
>> unnecessary however it turns out that due to .net support for implicit
>> casts there are some fringe cases where if (variable == null) will
>> behave differently to if (null == variable) apparently. Most of the
>> developers used if (variable == null) though in spite of the coding
>> standard because it was more intuitive.
>>
>>
> I think this originates with checks against literal values instead of
> against null when using value instead of reference equality.
>

No, I think this comes from the fact that C++ allows assignments in
expressions, therefore you can write:

if (a = NULL) ...

when you actually mean

if (a == NULL) ...

Reversing the arguments avoids this pitfall. Obviously, this is not
necessary in Java.

-- 
Cédric

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to