Java中参数的执行顺序保证? [英] Order of execution of parameters guarantees in Java?
问题描述
在 C
中给出以下函数调用:
Given the following function call in C
:
fooFunc( barFunc(), bazFunc() );
执行顺序barFunc
和未指定BazFunc
,因此可以在 bazFunc()$之前调用
barFunc()
c $ c>或 bazFunc()
之前 barFunc()
in C
。
The order of execution of barFunc
and BazFunc
is not specified, so barFunc()
may be called before bazFunc()
or bazFunc()
before barFunc()
in C
.
Java
指定函数参数表达式的执行顺序或类似 C
是未指定的?
Does Java
specify an order of execution of function argument expressions or like C
is that unspecified?
推荐答案
来自 Java语言规范(关于表达式):
15.7.4从左到右评估参数列表
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.
这篇关于Java中参数的执行顺序保证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!