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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2201688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:01:27  来源:igfitidea点击:

Order of execution of parameters guarantees in Java?

javaoperator-precedencespecificationsjls

提问by tpdi

Given the following function call in C:

鉴于以下函数调用C

fooFunc( barFunc(), bazFunc() );

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

barFunc和的执行顺序BazFunc没有指定,因此barFunc()可以在in之前bazFunc()bazFunc()之前调用。barFunc()C

Does Javaspecify an order of execution of function argument expressions or like Cis that unspecified?

是否Java指定函数参数表达式的执行顺序或类似C的未指定?

回答by Michael Easter

From the Java Language Specification(on Expressions):

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

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.

15.7.4 从左到右评估参数列表

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