作者:kkka姐姐_244 | 来源:互联网 | 2023-09-11 10:34
Icantseeanythingfunctionallywrongintermsofwhatgetsexecuted,butIvejustwastedanhour
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).
是否有任何东西可以以不同的方式配置以显示正确的行?(我正在使用最新的Android Studio,我认为它可能不稳定,但我确信我以前在Eclipse上看到过类似的行为,但我从来没有花时间跟踪它;也许是java的东西)。
3 个解决方案