gpt4 book ai didi

java - 表达式包含 "at most one side effect, as its outermost operation"是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:08:49 26 4
gpt4 key购买 nike

Java Language Spex 15.7 :

Code is usually clearer when each expression contains at most one side effect, as its outermost operation

这是什么意思?

最佳答案

这意味着每个表达式应该一次完成一个任务。

考虑以下两个声明:

int a = 10;
int b = 20;

现在的任务是将这两个int相加并将b递增1。有两种方法可以做到。

int c = a + b++;

int c = a + b;
b++;

JLS更喜欢并推荐后者。

关于java - 表达式包含 "at most one side effect, as its outermost operation"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12619225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com