Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
object Foo {
var initialized = 0
// This only happens once regardless of how many times Foo.fetch() is called
initialized = initialized + 1
def fetch(): Integer = initialized
class Foo {
println(s"initialized: ${Foo.fetch()}")
new Foo // prints "initialized: 1"
new Foo // prints "initialized: 1"
new Foo // prints "initialized: 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.