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

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

fooFunc( barFunc(), bazFunc() );

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

Java是指定函数参数表达式的执行顺序,还是像 C那样未指定?

14820 次浏览

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.