I am getting NullPointerException
from the below line sometimes.
System.out.println("Date::"+ row != null ? row.getLegMaturityDate() : "null");
After adding brackets, it is fine.
System.out.println("Date::"+ (row != null ? row.getLegMaturityDate() : "null"));
Please clarify me the behavior. Thanks in advance.
"Date::" + row
is never null, although row
sometimes is.
That is, "Date::"+ row != null
is equivalent to ("Date::"+ row) != null
which is always true.
It's a matter of operator precedence. Christoffer Hammarström has the executive summary. See this page http://bmanolov.free.fr/javaoperators.php for more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With