Created
January 14, 2015 05:44
-
-
Save ostretsov/b81b9a7dd72e87af54f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BaseIntQueue { | |
private val buffer = new ArrayBuffer[Int] | |
def put(x: Int) = buffer += x | |
def get() = buffer.remove(0) | |
} | |
trait Double extends BaseIntQueue { | |
override def put(x: Int) = super.put(x * 2) | |
} | |
trait Inc extends BaseIntQueue { | |
override def put(x: Int) = super.put(x + 1) | |
} | |
val q = new BaseIntQueue with Double with Inc | |
q.put(0) | |
q.put(10) | |
println(q.get()) // outputs 2 | |
println(q.get()) // and 22 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment