I am trying to define val inside the constructor of a class, but I am not making it work. This is a pretty intensive calculation, so I don't want to run it twice. I saw this in the following link, but when I try to do this with this code, it does not work (I still do not get the "application does not accept parameters"): How do you define the local var / val variable in the main 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 would 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 "the application does not accept parameters." How should I do it?
scala
Oscar Godson Sep 27 '17 at 19:30 2017-09-27 19:30
source share