Scala的try表达式和match表达式

一 try 表达式



 
二 match表达式


 
三 实例
  1. object try_match {
  2. val result_try =try{
  3. Integer.parseInt("dog")
  4. }catch{
  5. case _=>0
  6. }finally{
  7. println("always be printed")
  8. }//> always be printed
  9. //| result_try : Int = 0
  10. val code =3//> code : Int = 3
  11. val result_match=code match{
  12. case1=>"one"
  13. case2=>"two"
  14. case _ =>"others"
  15. }//> result_match : String = others
  16. }

猜你喜欢

转载自cakin24.iteye.com/blog/2390436
今日推荐