[英]Is println method accessor or mutator in JAVA?
In System.out.println
, println
is a accessor or mutator method in JAVA ? 在
System.out.println
, println
是JAVA中的访问器还是mutator方法?
Thank you.... 谢谢....
I would say it's neither. 我会说它不是。 It only exists for its side effects ;
它只存在副作用 ; it is not obliged to do anything at all to the internal state of
System.out
(which is what accessors and mutators are about). 它没有义务对
System.out
的内部状态做任何事情(这是访问者和变更者的意思)。
It's not an accessor, because it doesn't return a value (it's void
). 它不是访问器,因为它不返回值(它是
void
)。 One could argue that it's a mutator, because it modifies the state of the underlying I/O system (it has side effects), but it's not a clear-cut distinction, because is not modifying the state of the System
class or any of its instances. 有人可能认为它是一个mutator,因为它修改了底层I / O系统的状态(它有副作用),但它不是一个明确的区别,因为它不是修改
System
类或其任何一个的状态实例。
The accessor/mutator distinction generally applies to methods that return a value obtained from an object's attributes (accessors) or methods that modify those attributes (mutators), but this is not the case for println()
, the state being modified (an output stream) lies outside of the class. accessor / mutator的区别通常适用于返回从对象的属性(访问器)或修改这些属性(mutators)的方法获得的值的方法,但
println()
的情况不是这样,正在修改的状态(输出流) )在课堂之外。
No. Accessors are "getXXX", mutators are "setXXX". 没有。访问者是“getXXX”,mutators是“setXXX”。 println is neither.
println既不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.