Here is Scala code:
class FullDescription(val description: String)
class Logger {
val description = //?????
def onAttach(description: String) =
description = new FullDescription(description)
// val lazy description = onAttach(???) --
// ops! we don't know its actual argument,
// besides we should be able to make
// val description be evaluated from onAttach(...) and not vise versa
}
It's given that for any class Logger
it's guaranteed the method onAttach
will be called only once. But it's unknown when the method onAttach
will be called.
Is it possible to remain val description
immutable and how do I do that? A lazy
evaluation or something else?