Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def isType(x: Any): Boolean = x match {
case p: String => true
case p: Int => true
case _ => false
}
def isType2(x: Any): Boolean = {
if (x.isInstanceOf[String]) {
return true
} else if (x.isInstanceOf[Int]) {
return true
} else {
return false
}
}
println(isType(1))
println(isType(false))
println(isType2(1))
println(isType2(false))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment