Option的解释: Represents optional values. Instances of Option are either an instance of scala.Some or the object None.

Option[A] (sealed trait) 有两个取值:
    1. Some[A] 有类型A的值
    2. None 没有值

Option一般有两种用法:
    1. 模式匹配
         Option[A] option
         option match {
             case Some(a) => a
             case None => "?"
         }

 

    2. map
option map( o => "?" ).getOrElse("默认值")
 
Some的解释: Class Some[A] represents existing values of type A.

Some[A] some是一定有值的, some.get获取值,如果没有值, 会报异常. Predef.NoSuchElementException   if the option is empty.
 

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2021-10-20
  • 2021-08-05
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2021-09-24
  • 2022-12-23
  • 2021-10-12
  • 2021-11-14
  • 2021-11-24
相关资源
相似解决方案