java - 在方法调用期间修改参数时是否有任何保证?

标签 java methods jvm arguments

在 Java 中,当将参数传递给方法并修改传递的参数时,方法调用期间是否保证结果是预期的?
例如
a.method(++i);

是否保证例如在method中变量i将更新 值(value)?

或者a.method(i++)method是在自增之后还是之前得到i的值?

对于所有类似的情况也是一样的。
我记得这在 C++ 中是被禁止的,因为特定于实现,但也许我记错了。

最佳答案

前缀/后缀递增/递减运算符的 java 语言规范:

... the value 1 is added to the value of the variable and the sum is stored back into the variable ... The value of the prefix increment expression is the value of the variable after the new value is stored.

... the value 1 is added to the value of the variable and the sum is stored back into the variable ... The value of the postfix increment expression is the value of the variable before the new value is stored.

我觉得已经很清楚了。该函数将在前缀情况下获取增量值,而不是在后缀情况下。

关于java - 在方法调用期间修改参数时是否有任何保证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15074309/

相关文章:

java - 如何调用指定编号的方法发生异常的次数

java - 附加到已经运行的 JVM

java - JVM 崩溃..如何获取错误日志或核心转储

java - 加载具有父子关系的类时出现 LinkageError

java - 如何找到矩形内某个位置对应的子三角形

actionscript - 使用 ...(rest) 参数将参数从数组传递到 Actionscript 方法

JavaScript 对象 - 构造后对象值未定义

java - 如何用 Java 编写正确的微基准测试?

java - tomcat 在服务器重启时不反射(reflect) java 更改

java - 系统输出,系统错误 : often temporary debugging statements warning