I'm trying ot define a val inside a Class' constructor but I'm not getting it to work. It's a fairly intense computation so I don't want to run it twice. I saw this the following link but when I try to do that with this code it doesnt work (i get "application does not take parameters" still): How do you define a local var/val in the primary constructor in Scala?
class MyModel(
val foo: String,
val bar: String,
val baz: String,
) extends db.BaseModel {
def this() = this(
foo = "",
bar = "",
baz = ""
)
def this(
foo: SomeModel,
bar: String,
baz: String,
) = {
this(
someModel.id,
doSomeComplexComputation(),
doSomeComplexComputation(),
)
}
I'd like to have something like:
class MyModel(
val foo: String,
val bar: String,
val baz: String,
) extends db.BaseModel {
def this() = this(
foo = "",
bar = "",
baz = ""
)
def this(
foo: SomeModel,
bar: String,
baz: String,
) = {
val complexCalcSaved = doSomeComplexComputation()
this(
someModel.id,
complexCalcSaved,
complexCalcSaved,
)
}
But as I mentioned above I get "application does not take parameters". How do I go about this?