Side effect--what's this?

后端 未结 5 1522
天命终不由人
天命终不由人 2020-11-27 16:59

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

If you\'re calling an EL function that doesn\'t return anything, then you\

5条回答
  •  天涯浪人
    2020-11-27 17:38

    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.

    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.

提交回复
热议问题