Java中参数的执行顺序保证?

发布于 2024-08-20 15:23:28 字数 370 浏览 2 评论 0原文

给定 C 中的以下函数调用:

fooFunc( barFunc(), bazFunc() );

barFuncBazFunc 的执行顺序未指定,因此 barFunc() 可以在 bazFunc() 之前调用,或者在 C 中在 barFunc() 之前调用 bazFunc()

Java 是否指定了函数参数表达式的执行顺序,或者像 C 一样未指定?

Given the following function call in C:

fooFunc( barFunc(), bazFunc() );

The order of execution of barFunc and BazFunc is not specified, so barFunc() may be called before bazFunc() or bazFunc() before barFunc() in C.

Does Java specify an order of execution of function argument expressions or like C is that unspecified?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风月客 2024-08-27 15:23:28

来自 Java 语言规范(关于表达式):

15.7.4 参数列表从左到右计算

在方法或构造函数调用中
或类实例创建表达式,
参数表达式可能出现在
括号,用逗号分隔。
每个参数表达式似乎是
在任何部分的任何部分之前进行全面评估
其右侧的参数表达式。

From the Java Language Specification (on Expressions):

15.7.4 Argument Lists are Evaluated Left-to-Right

In a method or constructor invocation
or class instance creation expression,
argument expressions may appear within
the parentheses, separated by commas.
Each argument expression appears to be
fully evaluated before any part of any
argument expression to its right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文