Skip to content

Instantly share code, notes, and snippets.

@RSchulz
Last active Aug 29, 2015
Embed
What would you like to do?
// 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