Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created November 19, 2011 12:31
Show Gist options
  • Save tototoshi/1378797 to your computer and use it in GitHub Desktop.
Save tototoshi/1378797 to your computer and use it in GitHub Desktop.
scala.util.DynamicVariable のサンプル
import scala.util.DynamicVariable
object Main extends App {
val dyn = new DynamicVariable[Int](0)
println(dyn.value)
dyn.withValue(100) {
println(dyn.value)
dyn.withValue(200) {
println(dyn.value)
dyn.value_=(300)
println(dyn.value)
}
}
println(dyn.value)
}
/*
$ scalac dyn.scala && scala Main null
0
100
200
300
0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment