Skip to content

Instantly share code, notes, and snippets.

@RSchulz
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RSchulz/9338200 to your computer and use it in GitHub Desktop.
Save RSchulz/9338200 to your computer and use it in GitHub Desktop.
// 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