final class LazyValWithContext[T, Context] extends AnyRef
"Implements" a lazy val
field whose initialization expression can refer to implicit context information of type Context
.
The "val" is initialized upon the first call to get, using the context information supplied for this call,
like a lazy val
.
Instead of a plain lazy val field without context
class C { lazy val f: T = initializer }use the following code to pass in a
Context
:
class C { private[this] val _f: LazyValWithContext[T, Context] = new LazyValWithContext[T, Context](context => initializer) def f(implicit context: Context): T = _f.get }
This class implements the same scheme as how the Scala 2.13 compiler implements lazy val
s,
as explained on https://docs.scala-lang.org/sips/improved-lazy-val-initialization.html (version V1)
along with its caveats.
- See also
TracedLazyVal To be used when the initializer wants to log something using the logger of the surrounding class
ErrorLoggingLazyVal To be used when the initializer wants to log errors using the logger of the caller
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- LazyValWithContext
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- Protected
Instance Constructors
- new LazyValWithContext(initialize: (Context) => T)
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def get(implicit context: Context): T
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])