Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 11, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/106fec86e083c1755dcd to your computer and use it in GitHub Desktop.
Save shigemk2/106fec86e083c1755dcd to your computer and use it in GitHub Desktop.
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