Created
December 19, 2019 19:12
-
-
Save Vopaaz/e19d00210c91bc47e691464b08de19b2 to your computer and use it in GitHub Desktop.
Dynamically check the type of an object in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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