I recently started working with Eclipse for Android development. When debugging through the code, I noticed one strange behavior (at least compared to Visual Studio): After hitting return statement in the middle of the function, it doesn’t return immediately, but always jumps to the last return statement. For example:
String getTest(int i){
if (i == 0)
return "0";
return "-1";
}
Given i = 0, after hitting the first return statement, instead of jumping out of this function, it moves to the next return statement. However, it does return “0”, not “-1”. So, why this dummy step? It is confusing to me. Can anybody explain why?
This has to do with what exactly constitutes a “return” from a function. While this is platform dependent, a return typically has to:
Only the return value is different a compiler may choose to generate machine code (byte code in case of java) once and jump to it from different locations. Eclipse may be showing that jump.