Skip to content

Instantly share code, notes, and snippets.

@rshindo
Created March 23, 2017 11:15
Show Gist options
  • Save rshindo/3e8fcd65cc78c0c7b3b1a42f3d8ec458 to your computer and use it in GitHub Desktop.
Save rshindo/3e8fcd65cc78c0c7b3b1a42f3d8ec458 to your computer and use it in GitHub Desktop.
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())
}
@rshindo
Copy link
Author

rshindo commented Mar 23, 2017

Result:

BasicIntQueue.put
x=2
IntQueue.put
x=2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment