Scala Some v. Option

前端 未结 4 2034
甜味超标
甜味超标 2021-02-03 20:14

What\'s the difference between Some and Option?

scala> Some(true)
res2: Some[Boolean] = Some(true)

scala> val x: Option[Boolean]         


        
4条回答
  •  面向向阳花
    2021-02-03 20:56

    The basic idea of Option is to eliminate using Null in order have a default value and avoid a NullPointerException. So Option can have Some value or None (replacing Null). Check out this great explanation of Option: Scala Option explained

提交回复
热议问题