Skip to content

Instantly share code, notes, and snippets.

@Allan-Gong
Created October 11, 2016 23:01
Show Gist options
  • Save Allan-Gong/5b229b4117378b4559abdddc7a485c93 to your computer and use it in GitHub Desktop.
Save Allan-Gong/5b229b4117378b4559abdddc7a485c93 to your computer and use it in GitHub Desktop.
trait Foo { def bar: Int }
object F1 extends Foo { def bar = util.Random.nextInt(33) } // ok
class F2(val bar: Int) extends Foo // ok
object F3 extends Foo {
lazy val bar = { // ok
Thread.sleep(5000) // really heavy number crunching
42
}
}
// If you had
trait Foo { val bar: Int }
// You wouldn't be able to define F1 or F3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment