Reputation: 985
Suppose I have a String type lazy val :
Class LazyVals { lazy val message = "I am lazy on + " + System.currentTimeMillis().toString def changeLazy = { message + " Not!!" } }
Will changeLazy change the "evaluate once only" nature of message?
Upvotes: 0
Views: 180
Reputation: 38045
Code to calculate message
will be evaluated once only. You can't change this behavior.
currentTimeMillis
will be called only once. Concatenation message + " Not!!"
will be performed on each changeLazy
call with the same result, but can be optimized by jvm
.
Upvotes: 3