Skip to content

Instantly share code, notes, and snippets.

@Vopaaz
Created December 19, 2019 19:12
Show Gist options
  • Save Vopaaz/e19d00210c91bc47e691464b08de19b2 to your computer and use it in GitHub Desktop.
Save Vopaaz/e19d00210c91bc47e691464b08de19b2 to your computer and use it in GitHub Desktop.
Dynamically check the type of an object in Scala
import scala.reflect._
class Foo{
def expect[T: ClassTag](that: Any) = {
if (classTag[T].runtimeClass.isInstance(that)) {
doSomething
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment