2012-08-24 360 views

回答

5

这正是map是:

def convert(x: Option[Int]) = x map (_.toLong) 

其工作原理是这样的:

scala> convert(Some(1)) 
res0: Option[Long] = Some(1) 

scala> convert(None) 
res1: Option[Long] = None 

scala.Predef提供从IntRichInt的隐式转换,这是其中toLong方法得来的。