Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scala> def matchTypes(a: Any): String = a match {
- | case n: String => s"$n is a string"
- | case n: Int => s"$n is an integer"
- | case n: Boolean => s"$n is a boolean"
- | case _ => "some other type"
- | }
- matchTypes: (a: Any)String
- scala> matchTypes("hello")
- res0: String = hello is a string
- scala> matchTypes(124)
- res1: String = 124 is an integer
- scala> matchTypes(true)
- res2: String = true is a boolean
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement