class Test
{
public static int[ ] getArray() { return null; }
public static void main(String[] args)
{
int index = 1;
try
{
getArray()[index=2]++;
}
catch (Exception e){ } //empty catch
System.out.println("index = " + index);
}
}
cmbhatt
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Please tell the rule of this kind of expression evaluation...
15.7.1 Evaluate Left-Hand Operand First
15.7.2 Evaluate Operands before Operation
15.13.1 Runtime Evaluation of Array Access
An array access expression is evaluated using the following procedure:
(... snip ...)
Otherwise, if the value of the array reference expression is null, then a NullPointerException is thrown.
Hey is there any command in Java to trace the flow of control
The JLS covers the exact rules for evaluating expressions, but that's probably overkill for this case.
No answer yet!
all events occur in real time
The ++ operation is never executed, as we left the try block due to the npe.
15.7.2 Evaluate Operands before Operation
cmbhatt
Originally posted by Chandra Bhatt:
No answer yet!
![]()
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Why to not executing ++ operation. If it would pre ++.
.
15.7.2 Evaluate Operands before Operation
Doesn't this rule apply to this?
cmbhatt
Its after all "give and take" affair, remember!
Originally posted by megha joshi:
it seems as if you are blind to the effort...
When it becomes a give and drop...give and drop...give and drop affair..thats the time you see impatient replies and bad emoticons...
Originally posted by Ram Gopal:
Hey is there any command in Java to trace the flow of control within the program..like in C language?
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Originally posted by Chandra Bhatt:
I guess if someone took the name of this thread in another way. It was all about java expression evaluation not HUMAN.
Anyways thank you all for your replies.
------------------------
Yup, itz really disturbing to see people using "nested quotes"
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|