1.

How Scala defines the getter-setter methods for a field in a class?

Answer»

Scala automatically GENERATES getter-setter METHODS for each field DEFINED in a class after compilation. If there is a field as, value:Int

the getter-setter methods for this field would be, 

def value:Int = this.value // Getter def value_= (value:Int) = this.value = value // Setter


These methods are public for a public field whereas those are private for a private one.

However, the developer may create such public methods for a private field.

Also, they may declare getter-setter of a DIFFERENT pattern, like getXXX and setXXX .



Discussion

No Comment Found