Created
March 23, 2017 11:15
-
-
Save rshindo/3e8fcd65cc78c0c7b3b1a42f3d8ec458 to your computer and use it in GitHub Desktop.
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
abstract class IntQueue { | |
def get(): Int | |
val buf = new ArrayBuffer[Int] | |
def put(x: Int) = { | |
println("IntQueue.put") | |
println("x=" + x) | |
buf += x | |
} | |
} | |
class BasicIntQueue extends IntQueue { | |
def get() = 1 | |
override def put(x: Int) = { | |
println("BasicIntQueue.put") | |
println("x=" + x) | |
super.put(x) | |
} | |
} | |
trait Doubling extends IntQueue { | |
abstract override def put(x: Int) = super.put(x * 2) | |
} | |
object Main extends App { | |
val p = new BasicIntQueue with Doubling | |
p.put(1) | |
println(p.get()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
BasicIntQueue.put
x=2
IntQueue.put
x=2