Difference between Option(value) and Some(value)

后端 未结 2 857
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 09:00

I am new to scala !

My question is, if there is case class that contains a member

myItem:Option[String]

When i construct the class,

2条回答
  •  时光取名叫无心
    2021-01-31 09:10

    Option(x) is basically just saying if (x != null) Some(x) else None

    See line 25 of the Source code:

    def apply[A](x: A): Option[A] = if (x == null) None else Some(x)
    

提交回复
热议问题