Created
May 30, 2019 15:27
-
-
Save ben-ng/6b99bb45056882ee0eb894a5cb869e65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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