class Lazy[A](thunk : () => A) { lazy val body = thunk()} object Lazy { def lazy[A](x : => A) = new Lazy(() => x) def force[A](x : Lazy[A]) = x.body} object Main { def getX() = { println("hello") 3 } def main(args: Array[String]) { import Lazy._ val x = lazy(getX()) println("start") println(x) println(x) println(x) }}
Standard input is empty
Main.scala:6: error: identifier expected but 'lazy' found. def lazy[A](x : => A) = new Lazy(() => x) ^ Main.scala:17: error: illegal start of simple expression val x = lazy(getX()) ^ two errors found
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!