Skip to content

Instantly share code, notes, and snippets.

@nairbv
Created December 12, 2013 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nairbv/7923811 to your computer and use it in GitHub Desktop.
Save nairbv/7923811 to your computer and use it in GitHub Desktop.
An example of using a Manifest to get around type erasure
scala> def foo[T : Manifest](a : List[T]) = {
| val m = implicitly[Manifest[T]]
| val I = classOf[Int]
| val S = classOf[String]
| m.erasure match {
| case I => "hi"
| case S => "bye"
| case _ => "whatever"
| }
| }
foo: [T](a: List[T])(implicit evidence$1: Manifest[T])java.lang.String
scala> foo(List(1,2,3))
res6: java.lang.String = hi
scala> foo(List("blah"))
res7: java.lang.String = bye
scala> foo(List(1.2))
res8: java.lang.String = whatever
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment