Skip to content

Instantly share code, notes, and snippets.

@wrobstory
Last active August 29, 2015 14:08
Show Gist options
  • Save wrobstory/a501e1ff81bd026b46ac to your computer and use it in GitHub Desktop.
Save wrobstory/a501e1ff81bd026b46ac to your computer and use it in GitHub Desktop.
Type safety!
scala> val foo = Map("one" -> List("one", "two"))
foo: scala.collection.immutable.Map[String,List[String]] = Map(one -> List(one, two))
scala> foo.get("one").asInstanceOf[Option[Int]]
res1: Option[Int] = Some(List(one, two))
scala> val bar:Option[Int] = Some(List("one", "two"))
<console>:7: error: type mismatch;
found : List[String]
required: Int
val bar:Option[Int] = Some(List("one", "two"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment