Beware of these null check gotchas.
Consider this code -
|
|
The above code shows expected behaviour. Nothing is printed since if(sum)
returns false
.
Now, try the code below.
|
|
It can throw off your calculations by a wide margin.
Strange but true null >= 0
.
But, null > 0
and null == 0
both return false
.
To work-around the problem always use the comparison directly in if
statement or do an explicit Boolean conversion before the comparison.