Skip to content

Instantly share code, notes, and snippets.

@paulp
Created February 5, 2014 23:33
Show Gist options
  • Save paulp/8835608 to your computer and use it in GitHub Desktop.
Save paulp/8835608 to your computer and use it in GitHub Desktop.
trait Foo
class Ev[T]
case class Bar[A](xs: Ev[A], f: A => Unit) extends Foo
object Test {
def main(args: Array[String]) {
val foo: Foo = new Bar(new Ev[Int], println(_: Int))
// This is disallowed.
// foo match { case x: Bar[a] => x.f(x.xs) }
// This isn't.
foo match { case Bar(xs, f) => f(xs) }
}
}
// java.lang.ClassCastException: Ev cannot be cast to java.lang.Integer
// at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:105)
// at Test$$anonfun$1.apply(a.scala:7)
// at Test$.main(a.scala:12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment