Give the simple class
class MyClass {
private var myVar: String = _
}
How can I generate the setters and getters for myVar
?
The Code | Generate
menu shows:
IntelliJ
version: 14.1.5
OS: OS X 10.10.5
@Zoltán is right - getters and setters are not common in Scala because:
final private[this] val
).var someField
to private var _someField
, def someField = this._someField
and def someField_=(value: String) = { this._someField = value }
and not have consumers update their code. In other words, the change is source compatible (though I believe it is not binary compatible).If you need Java bean style getters and setters simply annotate the field with @BeanProperty
and scalac will generate the getter and setter for you:
import scala.beans.BeanProperty
class MyClass {
@BeanProperty
var myVar: String = _
}
Note that in order to get the is
getters and setters for a boolean property you need to use BooleanBeanProperty
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With