Java:在一行中增加多个 ++.哪个先?

编程入门 行业动态 更新时间:2024-10-27 17:14:16
本文介绍了Java:在一行中增加多个 ++.哪个先?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

嘿,我有以下两行代码:

Hey, I have the following two lines of code:

result[i] = temp[i] + temp[i + 1] + " " + temp[i + 2];
i += 2;

我想知道这行代码是否会做同样的事情:

I am wondering if this line of code would do the same:

    result[i] = temp[i] + temp[i++] + " " + temp[i++];

我可以确定 每个 VM 都会从左到右处理该行吗?谢谢,托比

Can I be sure, that EVERY VM would process the line from the left to the right? Thanks, Tobi

推荐答案

来自 Java 语言规范:

Java 编程语言保证运算符的操作数以特定的求值顺序进行求值,即从左到右.

The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.

建议代码不要过分依赖此规范.当每个表达式最多包含一个副作用(作为其最外层操作)时,代码通常会更清晰,并且当代码不依赖于从左到右计算表达式的结果是哪个异常出现时.

It is recommended that code not rely crucially on this specification. Code is usually clearer when each expression contains at most one side effect, as its outermost operation, and when code does not depend on exactly which exception arises as a consequence of the left-to-right evaluation of expressions.

这篇关于Java:在一行中增加多个 ++.哪个先?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 16:33:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1158553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!