方法并发

huangapple go评论80阅读模式
英文:

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).

huangapple
  • 本文由 发表于 2020年8月27日 22:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63618443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定