0

The scenario: Java uses the stack to execute the method with instructions. There is a methodA which contains a methodB, when invoke the methodA, the current Thread's Stack will create a new Stack-Frame for the methodA, when it encounter the methodB, it still does the same thing for methodB, and I understand that each frame contains the local variable table and operand stack, I can check that methodB use the local variable table to get value from the methodA, But how methodA get the methodB's return value(execution result)? I didn't find this from the Java doc.

jackzong
  • 3
  • 1

1 Answers1

0

The return value of methodB is pushed into the operand stack of methodA.

Reference (emphasis mine):

The current frame (ยง2.6) is used in this case to restore the state of the invoker, including its local variables and operand stack, with the program counter of the invoker appropriately incremented to skip past the method invocation instruction. Execution then continues normally in the invoking method's frame with the returned value (if any) pushed onto the operand stack of that frame.

dejvuth
  • 6,986
  • 3
  • 33
  • 36