scala - How to create private fields that my functions will return -
my class looks like:
class webconfig(config: config) { def this() { this(configfactor.load()) } def dbport = config.getint("mysql.port") }
i don't when call dbport, has call , cast config each , every time.
so want create private fields , set them in constructor, calling dbport return private field has.
how can this?
i tried creating private var getting 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
can't write this:
class webconfig(config: config) { def this() { this(configfactor.load()) } val dbport = config.getint("mysql.port") }
it read config parameter 1 time.
Comments
Post a Comment