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

问题描述

有人能告诉我下面这行副作用"的意思吗?

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

如果您调用一个不返回任何内容的 EL 函数,那么您只是为了它的副作用而调用它.

推荐答案

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

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.

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

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