Skip to content

Instantly share code, notes, and snippets.

@MarounMaroun
Created November 21, 2017 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarounMaroun/bd0dc67dda9f658cf95a72d340c692c4 to your computer and use it in GitHub Desktop.
Save MarounMaroun/bd0dc67dda9f658cf95a72d340c692c4 to your computer and use it in GitHub Desktop.
Scala singleton example using object
object Singleton {
private var i = 0
def create(): Int = {
i += 1
i
}
}
Singleton.create() // 1
Singleton.create() // 2
Singleton.create() // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment