Originally Posted by SaurabhUpadhyay
1. It is throwing an exception because it CANNOT evaluate the expression, not because the whole expression evaluates to null
: there is nothing wrong, per se, with an expression evaluating to null
or even concatenating a null
with a String
2. It cannot evaluate the expression because an object reference WITHIN the expression entry.getBirthday().getValue() evaluates to null
AND is being used to reference a scoped member (field or method) of that object.
Examine the expression and review the steps taken at runtime to evaluate it.
Hint: The runtime starts by accessing an object through a reference. Then it calls a method of that object which returns a reference to another object...
Break the expression up to check if either of these objects is null
(The runtime finally calls a method on the second object which returns your final value. Even if this final value is an object, there would be no problem with it being null
, as it is not being used to access a member. So your if
statement is checking the wrong value.)