Last active
August 29, 2015 13:56
-
-
Save RSchulz/9338200 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
// Scala WTF #15189... | |
scala> trait A { } | |
defined trait A | |
trait B { } | |
defined trait B | |
val a1 = new A { } | |
a1: A = $anon$1@33c239aa | |
// WTF? The compiler accepts this? | |
val b1 = a1.asInstanceOf[A with B] | |
b1: A with B = $anon$1@33c239aa | |
// Eventually it catches on... | |
scala> val b2 = b.asInstanceOf[B] | |
java.lang.ClassCastException: $anon$1 cannot be cast to B | |
scala> val b3 = a.asInstanceOf[B with A] | |
java.lang.ClassCastException: $anon$1 cannot be cast to B | |
// But it still believes its own lie! | |
scala> val b4 = b1.asInstanceOf[A with B] | |
b4: A with B = $anon$1@33c239aa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment