英文:
Method concurrency
问题
方法2是否总是在方法1完全执行之后才开始?
英文:
Let's say I have two methods in a method
void hello(){
method1();
method2();
}
Does method2 start only after complete execution of method1 all the time?
答案1
得分: 2
是的,那就是该语言的定义。如果没有涉及线程,一个方法在下一个方法被调用之前需要先返回。
英文:
yes, that's the definition of the language. If there is no threading involved, one method needs to return before the next one is invoked.
答案2
得分: 1
是的,这是有保证的。方法的主体是一个代码块,而JLS 14.2中规定:
> 通过按从左到右的顺序执行每个局部变量声明语句和其他语句来执行代码块。
英文:
Yes. It is guaranteed. The body of a method is a block, and the JLS 14.2 states:
> A block is executed by executing each of the local variable declaration statements and other statements in order from first to last (left to right).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论