Java – eclipse debugging: continue after the return statement?

I recently started using eclipse for Android development During code debugging, I noticed a strange behavior (at least compared with visual studio): after clicking the return statement in the middle of the function, it will not return immediately, but always jump to the last return statement For example:

String getTest(int i){
  if (i == 0)
     return "0";
  return "-1";
}

Given I = 0, after clicking the first return statement, it will not jump out of this function, but move to the next return statement However, it does return "0" instead of "- 1" So why this virtual step? It's confusing to me Who can explain why?

Solution

This is related to what exactly constitutes the "return" of the function Although this depends on the platform, the return must usually:

>Copy the return code to a well-known register (eax in x86) > pop the return address from the activation record stack > reset the stack pointer (and base pointer)

Only if the return value is different, the compiler can choose to generate machine code (byte code in the case of Java) once and jump to it from different locations Eclipse may display a jump

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>