Tony Collen wrote:
On Fri, 7 Mar 2003, Berin Loritsch wrote:


Jeff Turner wrote:

Hi,

Quick question. Why do people put null checks backwards:

if ( null != this.inputSource ) {

IMHO it is harder to read than

if ( this.inputSource != null ) {

and means exactly the same thing.


Likewise, I've seen something like this in code... can't remember if it's
anywhere in Cocoon:

if ( "something".equals(stringToCompare) {
   ...
}

IMO it seems more straightforward and easier to read if it's:

if ( stringToCompare.equals("something") ) {
   ...
}

Is this just a matter of style as well?

no, this is substantially different.


the first will never trigger a nullpointerexception, no matter what the stringToCompare is since String.equals() is Null-aware and fails nicely with a 'false' boolean if a string is compared with a null.



Reply via email to