Skip to content

Instantly share code, notes, and snippets.

@bhudgeons
Forked from paulp/named.scala
Last active August 29, 2015 14:07
Show Gist options
  • Save bhudgeons/dc3cc0a14c4e5c82818e to your computer and use it in GitHub Desktop.
Save bhudgeons/dc3cc0a14c4e5c82818e to your computer and use it in GitHub Desktop.
class A {
def f(x: Int, y: Int) = ((x, y))
def name = "A"
}
class B extends A {
override def f(y: Int, x: Int) = ((y, x))
override def name="B"
}
object Test {
val b = new B
def main(args: Array[String]): Unit = {
// the upcast doesn't "undo" the override, of course
println((b:A).name) // B
println((b:B).name) // B
// wrong! should be (2,1)
println((b: A).f(x = 1, y = 2)) // (1,2)
println((b: B).f(x = 1, y = 2)) // (2,1)
println((b: A).f(1, 2)) // (1,2)
println((b: B).f(1, 2)) // (1,2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment