Page 1 of 1
About Question enthuware.ocpjp.i.v11.2.1311 :
Posted: Tue Jun 30, 2020 3:36 pm
by lucasbeer
A NullPointerException never occurs because the index expression must be completely evaluated before any part of the indexing operation occurs, and that includes the check as to whether the value of the left-hand operand is null.
Could someone please explain this to me in clearer terms?
Re: About Question enthuware.ocpjp.i.v11.2.1311 :
Posted: Wed Jul 01, 2020 4:21 am
by admin
While evaluating the expression a [ m1() ];, the JVM has to invoke the method m1() first. But the call to m1 throws Exception. So, before the JVM could access any element of a (which is null), it gets the Exception thrown from the call to m1. So, there is no NullPointerException.