KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: What's the (hidden) cost of lazy val? (Scala) Scala allows the definition of lazy values lazy val maybeUnusedValue = someCostlyInitialization where someCostlyInitialization is evaluated only on the first use of maybeUnusedValue . That is, it is evaluated at most once, and if maybeUnusedValue is never used, it is also never evaluated at all. Is this threadsafe? What are the performance implications of this? If this is to be threadsafe, it has to use some kind of syncronization / use Java volatile in some way. Unfortunately the Scala language specification says nothing about this.
Tags (comma-separated)
Save Edits
Cancel