Guest User

Untitled

a guest
Oct 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. scala> import scala.util.control.Exception.allCatch
  2. import scala.util.control.Exception.allCatch
  3.  
  4. scala> val x: Option[Int] = allCatch.opt { "123".toInt }
  5. x: Option[Int] = Some(123)
  6.  
  7. scala> x
  8. res0: Option[Int] = Some(123)
  9.  
  10. scala> :type x
  11. Option[Int]
  12.  
  13. scala> Console println x
  14. Some(123)
  15.  
  16. scala> x
  17. res2: Option[Int] = Some(123)
  18.  
  19. scala> val a: Int = x
  20. <console>:9: error: type mismatch;
  21. found : Option[Int]
  22. required: Int
  23. val a: Int = x
  24. ^
  25.  
  26. scala>
Add Comment
Please, Sign In to add comment