Scala Option implicit conversion - Bad practice or missing feature?

后端 未结 3 1176
面向向阳花
面向向阳花 2021-01-22 18:16

I represented my data model as case classes typing values that may be null as Option.

case class Document(id: Long, title: String, subtitle: Option[String])
         


        
3条回答
  •  情歌与酒
    2021-01-22 18:34

    That's a pretty dangerous implementation:

    scala> val s: String = null
    s: String = null
    
    scala> Document(123, "The Title", s)
    res2: Document = Document(123,The Title,Some(null))
    

提交回复
热议问题