Hi,
I have the following snippet of code that is causing me bother, where currentRate and secondCurrentRate are Double objects, correctly defined:
(currentRate != null && secondCurrentRate != null) ? currentRate * secondCurrentRate : null;
This should check each each Double for null-ness and assign the value null accordingly. However, if secondCurrentRate is null, this causes a NullPointerException. I have changed the snippet to this:
(currentRate == null | secondCurrentRate == null) ? null : currentRate * secondCurrentRate;
And this works as expected. My question is why is this happening? I could understand it if I was calling some method on the objects but my understanding was that NullPointerExceptions were thrown when a method was called on a null object. There is a null object but there is no method call.
Can anyone offer any insight into this? This is running in Java 5.