Skip to content

Instantly share code, notes, and snippets.

@dsugden
Created February 22, 2014 14:05
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 dsugden/9155379 to your computer and use it in GitHub Desktop.
Save dsugden/9155379 to your computer and use it in GitHub Desktop.
OO state
class Foo{
private var fooState = 0
def next:Int = { fooState = fooState + 1; fooState }
def getFooState:Int = fooState
}
val foo = new Foo()
foo.next
foo.next
val result = foo.next
println("foo="+foo.getFooState) // foo=3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment