If possible, I would stick with None , which is almost always the case. It is shorter and widely used. Option.empty allows you to specify the type of the base value, so use it when you need help with type inference. If the type is already known to the compiler, None will work as expected, however when defining a new variable
var a = None
will cause infering in a None.type which is unlikely that you wanted.
You can then use one of two ways to help conclude what you need
@ var a = Option.empty[String] a: Option[String] = None @ var a: Option[String] = None a: Option[String] = None @ var a = None: Option[String]
Another place when the compiler needs help:
List(1, 2, 3).foldLeft(Option.empty[String])((a, e) => a.map(s => s + e.toString))
(The code does not make sense, but only as an example) If you omit the type or replace it with None the battery type will be displayed in Option[Nothing] and None.type respectively.
And for me personally, this is where I would go with Option.empty , for other cases I use Option.empty use None .
source share