Can I define “method-private” fields in Scala?
Given this situation: object ResourceManager { private var inited = false def init(config: Config) { if (inited) throw new IllegalStateException // do initialization inited = true } } Is there any way that I could make inited somehow “private to init()”, such that I can be sure that no other method in this class will ever be able to set inited = false ? Debilski Taken from In Scala, how would you declare static data inside a function? . Don’t use a method but a function object: val init = { // or lazy val var inited = false (config: Config) => { if (inited) throw new IllegalStateException