Back to Scala3

The @threadUnsafe annotation

docs/_docs/reference/other-new-features/threadUnsafe-annotation.md

3.8.3428 B
Original Source

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.

Example

scala
import scala.annotation.threadUnsafe

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