Scala Option implicit conversion - Bad practice or missing feature?

后端 未结 3 1210
面向向阳花
面向向阳花 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:42

    Most problems pointed out earlier can easily be fixed with a small change to the implicit: implict def autoOpt[T](x: T): Option[T] = Option(x)

    I can't really think of a good reason scala does not provide this conversion as a part of the default library of implicit converters.

    The fact that implicts make code harder to understand can be used as an argument against using any implicit, but not as one against using this particular one

提交回复
热议问题