-
-
Save bhudgeons/dc3cc0a14c4e5c82818e 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
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