My class currently looks like:
class WebConfig(config: Config) {
def this() {
this(ConfigFactor.load())
}
def dbPort = config.getInt("mysql.port")
}
I don't like that when I call dbPort, it has to call and then cast the config each and every time.
So I want to create private fields and set them in the constructor, so then calling dbPort will simply return what a private field has.
How can I do this?
I tried creating a private var but I am getting this error:
class WebConfig(config: Config) {
private var _dbPort: Int
def this() {
this(ConfigFactor.load())
_dbPort = config.getInt("mysql.port")
}
def dbPort: Int = _dbPort
}
Error:
abstract member may not have private modifier
lazy val dbPort = config.getInt("mysql.port")do exactly what you are trying to implement?