Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created October 24, 2013 16:33
Show Gist options
  • Save ryanlecompte/7140499 to your computer and use it in GitHub Desktop.
Save ryanlecompte/7140499 to your computer and use it in GitHub Desktop.
scala 2.10 type erasure
scala> class Foo[+A,+B](a: A, b: B)
scala> def hi[A: ClassTag, B: ClassTag](f: Foo[Any,Any]) = f match { case _: Foo[Int,Int] => println("hi"); case _ => println("bye") }
<console>:9: warning: non-variable type argument Int in type pattern Foo[Int,Int] is unchecked since it is eliminated by erasure
def hi[A: ClassTag,B: ClassTag](f: Foo[Any,Any]) = f match { case _: Foo[Int,Int] => println("hi"); case _ => println("bye") }
^
hi: [A, B](f: Foo[Any,Any])(implicit evidence$1: scala.reflect.ClassTag[A], implicit evidence$2: scala.reflect.ClassTag[B])Unit
scala> hi(new Foo("a","b"))
hi
@rkuhn
Copy link

rkuhn commented Oct 24, 2013

you are not using A and B here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment