Skip to content

Instantly share code, notes, and snippets.

@agushuley
Created October 2, 2012 06:26
Show Gist options
  • Save agushuley/3816779 to your computer and use it in GitHub Desktop.
Save agushuley/3816779 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 5, 1th task
class Counter {
private var counter: Int = 0;
def increment(): Int = {
if ( counter == Int.MaxValue ) {
counter = 0
} else {
counter += 1
}
counter
}
def current = counter
def current_= ( value: Int ) {
counter = value
}
}
var myCounter = new Counter()
myCounter.current
myCounter.increment()
myCounter.current
myCounter.current = Int.MaxValue
myCounter.current
myCounter.increment()
myCounter.current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment