本文介绍了副作用 - 这是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在下一行告诉我副作用的含义吗?

Could someone tell me the meaning of "side effect" in the following line?


推荐答案

副作用是除了计算和返回值之外的任何方法。实例或类字段值的任何更改都是副作用,就像在屏幕上绘制内容,写入文件或网络连接一样。

A side effect is anything a method does besides computing and returning a value. Any change of instance or class field values is a side effect, as is drawing something on the screen, writing to a file or a network connection.

严格来说,函数被定义为没有副作用 - 这就是Java使用方法一词的原因。没有返回值的真正函数将毫无意义。

Strictly speaking, a "function" is defined as not having side effects - which is why Java uses the word "method" instead. A real function with no return value would be pointless.

显然,没有返回值的方法必须具有某种副作用,证明其存在是正确的。设置方法就是一个例子 - 副作用是改变对象的内部状态。

Obviously, a method that does not have a return value must have some sort of side effect that justifies its existence. Set methods are an example - the side effect is changing the object's internal state.

这篇关于副作用 - 这是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 00:24