Created
February 22, 2014 14:05
-
-
Save dsugden/9155379 to your computer and use it in GitHub Desktop.
OO state
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
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