I can't see anything functionally wrong in terms of what gets executed, but I've just wasted an hour proving my code and the compiler are doing what they're supposed to.
Consider this code:
public int getAnswer(int a) {
int retval = 18;
int x = 25;
int y = 50;
while (a-- > 0) {
if (a == 3) {
retval = a;
return retval;
}
}
x = 10;
y = 20;
return 0;
}
Called with
int theAnswer = getAnswer(6);
Breakpoint both of the lines containing return
and before you run the code, try and predict the result, and therefore which line will be hit.
As you might imagine from the tone of my question, the wrong line is highlighted, but the right result is returned. If you step through the code, it dances around quite a bit.
Is there anything that can be configured differently such that the correct lines are displayed? (I'm using the latest Android Studio, which I appreciate is potentially unstable, but I'm sure I've seen similar behaviour on Eclipse a while back but I never spent the time then tracking it down; perhaps it's a java thing).
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…