在Java中描述实例和参数的方法的执行顺序? [英] Order of execution of methods describing an instance and an argument in Java?

查看:101
本文介绍了在Java中描述实例和参数的方法的执行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明中:

fooFunc().barFunc(bazFunc());

barFunc()显然不会执行,直到 bazFunc() fooFunc()已完成。

barFunc() can obviously not execute until both bazFunc() and fooFunc() have completed.

但执行顺序是 fooFunc() bazFunc()保证吗?

But is the order of execution of fooFunc() and bazFunc() guaranteed?

相关(但不同!)问题: Java中参数保证的执行顺序?

推荐答案

此文档是 15.12.4。方法调用的运行时评估

它说在运行时,方法调用需要五个步骤。首先,可以计算目标引用。首先,检查要调用的方法的可访问性。第四,找到要执行的方法的实际代码。第五,创建新的激活帧,必要时执行同步,并且控制转移到方法代码。

It says "At run-time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code."

在示例中, fooFunc()作为计算的一部分被调用目标引用, bazFunc()是参数表达式之一,因此必须首先调用 fooFunc()

In the example, fooFunc() is called as part of computing the target reference, and bazFunc() is one of the argument expressions, so fooFunc() must be called first.

这篇关于在Java中描述实例和参数的方法的执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆