I found a question about DynamicVariable:
When we should use scala.util.DynamicVariable?
Then I tried to make an example to use the DynamicVariable
object m {
class W {
def wrapper[T](f: => T) = W.dyn.withValue("Bye")(f)
}
object W {
private val dyn = new DynamicVariable[String]("Hello")
}
def main() = {
val w = new W()
w.wrapper {
println(1)
}
}
}
m.main()
It compiles successfully, but I have no ideas about how to extract the value assigned by the DynamicVariable
, does anyone have ideas about this?