Skip to content

Instantly share code, notes, and snippets.

@NomadBlacky
Last active August 13, 2018 06:08
Show Gist options
  • Select an option

  • Save NomadBlacky/50bcdcafaeac5d193dee300751f8e5e8 to your computer and use it in GitHub Desktop.

Select an option

Save NomadBlacky/50bcdcafaeac5d193dee300751f8e5e8 to your computer and use it in GitHub Desktop.
scala.reflect.ClassTag
@ def foo[T: scala.reflect.ClassTag](obj: Any): Unit = obj match {
case t: T => println(t.getClass.getName)
case _ => println("ng")
}
defined function foo
@ foo[Int](1)
java.lang.Integer
@ foo[String](1)
ng
@ foo[Int]("hoge")
ng
@ foo[String]("aa")
java.lang.String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment