加入main调用方法A,A调用B。那么栈内的元素应该是main A BB执行完了就要出栈,此时栈顶A开始执行;A执行完了就要出栈,此时栈顶main开始执行;main执行完了,栈空了,程序就结束了。
编译器原理摆在那里 不解释不出栈那还留着?当然是不管什么方法用完就OVER了啊
The Java stack is composed of stack frames (or frames). A stack frame contains the state of one Java method invocation. When a thread invokes a method, the Java virtual machine pushes a new frame onto that thread's Java stack. When the method completes, the virtual machine pops and discards the frame for that method. 如果不出栈就没法丢弃刚执行完的方法信息,也正好顺理成章执行栈顶元素(即invoking method的接下来内容)
main方法同样会