Work in Progress

We are still in the process of writing the documentation for Scala 3. You can help us to improve the documentation.

Are you searching for the Scala 2 documentation?

Scala 3 Language Reference

The @threadUnsafe annotation


A new annotation @threadUnsafe can be used on a field which defines a lazy val. When this annotation is used, the initialization of the lazy val will use a faster mechanism which is not thread-safe.


import scala.annotation.threadUnsafe

class Hello:
   @threadUnsafe lazy val x: Int = 1

Contributors to this page: