I have a variable in one of my scala classes, whose value is only set for the first time upon calling a specific method. The method parameter value will be the initial value of the field. So I have this:
classX {
private var value: Int= _
private var initialised = false
def f(param: Int) {
if (!initialised){
value = param
initialised = true
}
}
}
Is there a more scala-like way to do this? Options seem a bit too cumbersome...